Skip to content

Commit

Permalink
[fix] concurrent map iteration and map write
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Oct 18, 2024
1 parent 3463301 commit 813328f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion vngcloud/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

ljtime "github.com/cuongpiger/joat/timer"
lreq "github.com/imroc/req/v3"

lserr "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/sdk_error"
)

Expand Down Expand Up @@ -96,7 +97,7 @@ func (s *httpClient) WithReauthFunc(pauthOpt AuthOpts, preauthFunc func() (ISdkA
}

func (s *httpClient) DoRequest(purl string, preq IRequest) (*lreq.Response, lserr.IError) {
req := s.client.R().SetContext(s.context).SetHeaders(s.defaultHeaders).SetHeaders(preq.GetMoreHeaders())
req := s.client.R().SetContext(s.context).SetHeaders(s.getDefaultHeaders()).SetHeaders(preq.GetMoreHeaders())
if opt := preq.GetRequestBody(); opt != nil {
req.SetBodyJsonMarshal(opt)
}
Expand Down Expand Up @@ -216,6 +217,16 @@ func (s *httpClient) setAccessToken(pnewToken ISdkAuthentication) IHttpClient {
return s
}

func (s *httpClient) getDefaultHeaders() map[string]string {
s.mut.RLock()
defer s.mut.RUnlock()
if s.defaultHeaders == nil {
s.defaultHeaders = make(map[string]string)
}

return s.defaultHeaders
}

func newReauthFuture() *reauthFuture {
return &reauthFuture{
done: make(chan struct{}),
Expand Down

0 comments on commit 813328f

Please sign in to comment.