Make Client thread-safe & add docs #495

Merged
6543 merged 6 commits from :doc-concurrency into master 2021-03-04 20:19:56 +00:00
Showing only changes of commit 969df574f9 - Show all commits

View File

@ -153,7 +153,9 @@ func (c *Client) SetSudo(sudo string) {
// SetDebugMode is an option for NewClient to enable debug mode
func SetDebugMode() func(client *Client) {
return func(client *Client) {
client.mutex.Lock()
client.debug = true
client.mutex.Unlock()
}
}
@ -163,13 +165,11 @@ func (c *Client) getWebResponse(method, path string, body io.Reader) ([]byte, *R
fmt.Printf("%s: %s\nBody: %v\n", method, c.url+path, body)
}
req, err := http.NewRequestWithContext(c.ctx, method, c.url+path, body)
c.mutex.RUnlock()
if err != nil {
c.mutex.RUnlock()
return nil, nil, err
}
c.mutex.RUnlock()
resp, err := c.client.Do(req)
if err != nil {
return nil, nil, err