- 内嵌APICookie后,删除一些冗余的数据成员

This commit is contained in:
gazebo
2019-09-10 14:22:49 +08:00
parent a1c5ec77ff
commit 938b28e5a8
7 changed files with 21 additions and 36 deletions

View File

@@ -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,