You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this case, all the setter method should also be protected by the rw mutex right?
I write a simple demo as follows:
// Cookies method gets all cookies in the client instance.
// It uses a Read-Write mutex to make itself thread-safe.
func (c *Client) Cookies() []*http.Cookie {
c.mutex.RLock()
defer c.mutex.RUnlock()
return c.cookies
}
// SetCookies method sets an array of cookies in the client instance.
// These cookies will be added to all the request raised from this client instance.
//
// cookies := []*http.Cookie{
// &http.Cookie{
// Name:"go-resty-1",
// Value:"This is cookie 1 value",
// },
// &http.Cookie{
// Name:"go-resty-2",
// Value:"This is cookie 2 value",
// },
// }
//
// // Setting a cookies into resty
// client.SetCookies(cookies)
func (c *Client) SetCookies(cs []*http.Cookie) *Client {
c.mutex.Lock()
c.cookies = append(c.cookies, cs...)
c.mutex.Unlock()
return c
}
@jeevatkm I can help with this. Actually, I add the lock to some methods, such as SetQueryParams. However, it ends up failing the retry test. I tested 5 times, and it only succeeded once and passed all the tests. Maybe it's because the lock introduced extra time consumption.
All the exported fields will become getter methods,
e.g.,
client.BaseURL => client.BaseURL()
The text was updated successfully, but these errors were encountered: