Skip to content

Commit

Permalink
Add Clone function
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiante committed Mar 3, 2024
1 parent ae47677 commit 9152f3d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,25 @@ func (c *Client) GetClient() *http.Client {
return c.httpClient
}

// Clone returns a clone of the original client.
//
// Be carefull when using this function:
// - Interface values are not deeply cloned. Thus, both the original and the clone will use the
// same value.
// - This function is not safe for concurrent use. You should only use this when you are sure that
// the client is not being used by any other goroutine.
//
// Since v2.12.0
func (c *Client) Clone() *Client {
// dereference the pointer and copy the value
cc := *c

// lock values should not be copied - thus new values are used.
cc.afterResponseLock = &sync.RWMutex{}
cc.udBeforeRequestLock = &sync.RWMutex{}
return &cc
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Client Unexported methods
//_______________________________________________________________________
Expand Down

0 comments on commit 9152f3d

Please sign in to comment.