Skip to content

Commit

Permalink
refactor: embed mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
radulucut committed Jun 21, 2024
1 parent f20580f commit 4bc3d3d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (

// https://docs.api.colete-online.ro
type Client struct {
sync.Mutex
authURL string
apiURL string
authBasic string
authBearer string
authBearerExp time.Time
http *http.Client
mu sync.Mutex
timeNow func() time.Time
}

Expand All @@ -44,7 +44,6 @@ func NewClient(config Config) *Client {
timeNow: func() time.Time {
return time.Now()
},
mu: sync.Mutex{},
}
if config.UseProduction {
client.apiURL = "https://api.colete-online.ro/v1"
Expand All @@ -55,8 +54,8 @@ func NewClient(config Config) *Client {
}

func (c *Client) GetAuthBearer() (*string, error) {
c.mu.Lock()
defer c.mu.Unlock()
c.Lock()
defer c.Unlock()
if c.timeNow().After(c.authBearerExp) {
req, err := http.NewRequest(
"POST",
Expand Down

0 comments on commit 4bc3d3d

Please sign in to comment.