From 66a76ed93754bc4bc9c14e886ef31220f8a3a0fd Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Fri, 4 Dec 2020 23:18:33 +0100 Subject: [PATCH] Renamed repo, added go modules, protect access token from concurrent read access. --- client.go | 4 +++- demo/main.go | 2 +- go.mod | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 go.mod diff --git a/client.go b/client.go index e765a1c..a4797db 100644 --- a/client.go +++ b/client.go @@ -25,7 +25,7 @@ type Client struct { hostname string accessToken string expiresAt time.Time - m sync.Mutex + m sync.RWMutex } // ClientConfig is used to configure the Client. @@ -152,5 +152,7 @@ func (client *Client) performPost(url string, body interface{}) error { } func (client *Client) setRequestHeaders(req *http.Request) { + client.m.RLock() + defer client.m.RUnlock() req.Header.Set("Authorization", "Bearer "+client.accessToken) } diff --git a/demo/main.go b/demo/main.go index 65ccd22..17a6a2e 100644 --- a/demo/main.go +++ b/demo/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/pirsch-analytics/go-sdk" + "github.com/pirsch-analytics/pirsch-go-sdk" "log" "net/http" ) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9438f14 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/pirsch-analytics/pirsch-go-sdk + +go 1.15