fixed panic due to concurrent map writes

Fixes #36
This commit is contained in:
Jarek Kowalski
2020-08-17 19:47:58 -07:00
committed by Christoph Polcin
parent 9380631c29
commit 617404b525
4 changed files with 27 additions and 16 deletions

View File

@@ -9,6 +9,7 @@ import (
"os"
pathpkg "path"
"strings"
"sync"
"time"
)
@@ -17,7 +18,9 @@ type Client struct {
root string
headers http.Header
c *http.Client
auth Authenticator
authMutex sync.Mutex
auth Authenticator
}
// Authenticator stub
@@ -25,7 +28,7 @@ type Authenticator interface {
Type() string
User() string
Pass() string
Authorize(*Client, string, string)
Authorize(*http.Request, string, string)
}
// NoAuth structure holds our credentials
@@ -50,12 +53,12 @@ func (n *NoAuth) Pass() string {
}
// Authorize the current request
func (n *NoAuth) Authorize(c *Client, method string, path string) {
func (n *NoAuth) Authorize(req *http.Request, method string, path string) {
}
// NewClient creates a new instance of client
func NewClient(uri, user, pw string) *Client {
return &Client{FixSlash(uri), make(http.Header), &http.Client{}, &NoAuth{user, pw}}
return &Client{FixSlash(uri), make(http.Header), &http.Client{}, sync.Mutex{}, &NoAuth{user, pw}}
}
// SetHeader lets us set arbitrary headers for a given client