- 内嵌APICookie后,删除一些冗余的数据成员
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type APICookie struct {
|
||||
locker sync.RWMutex
|
||||
sync.RWMutex
|
||||
storeCookies map[string]string
|
||||
}
|
||||
|
||||
@@ -44,28 +44,28 @@ func (a *APICookie) SetCookieWithStr(cookieStr string) {
|
||||
}
|
||||
|
||||
func (a *APICookie) SetCookie(key, value string) {
|
||||
a.locker.Lock()
|
||||
defer a.locker.Unlock()
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
a.createMapIfNeeded()
|
||||
a.storeCookies[key] = value
|
||||
}
|
||||
|
||||
func (a *APICookie) GetCookie(key string) string {
|
||||
a.locker.RLock()
|
||||
defer a.locker.RUnlock()
|
||||
a.RLock()
|
||||
defer a.RUnlock()
|
||||
a.createMapIfNeeded()
|
||||
return a.storeCookies[key]
|
||||
}
|
||||
|
||||
func (a *APICookie) GetCookieCount() int {
|
||||
a.locker.RLock()
|
||||
defer a.locker.RUnlock()
|
||||
a.RLock()
|
||||
defer a.RUnlock()
|
||||
return len(a.storeCookies)
|
||||
}
|
||||
|
||||
func (a *APICookie) FillRequestCookies(r *http.Request) *http.Request {
|
||||
a.locker.RLock()
|
||||
defer a.locker.RUnlock()
|
||||
a.RLock()
|
||||
defer a.RUnlock()
|
||||
for k, v := range a.storeCookies {
|
||||
r.AddCookie(&http.Cookie{
|
||||
Name: k,
|
||||
|
||||
Reference in New Issue
Block a user