Skip to content

Commit 9152f3d

Browse files
committed
Add Clone function
1 parent ae47677 commit 9152f3d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

client.go

+19
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,25 @@ func (c *Client) GetClient() *http.Client {
11251125
return c.httpClient
11261126
}
11271127

1128+
// Clone returns a clone of the original client.
1129+
//
1130+
// Be carefull when using this function:
1131+
// - Interface values are not deeply cloned. Thus, both the original and the clone will use the
1132+
// same value.
1133+
// - This function is not safe for concurrent use. You should only use this when you are sure that
1134+
// the client is not being used by any other goroutine.
1135+
//
1136+
// Since v2.12.0
1137+
func (c *Client) Clone() *Client {
1138+
// dereference the pointer and copy the value
1139+
cc := *c
1140+
1141+
// lock values should not be copied - thus new values are used.
1142+
cc.afterResponseLock = &sync.RWMutex{}
1143+
cc.udBeforeRequestLock = &sync.RWMutex{}
1144+
return &cc
1145+
}
1146+
11281147
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
11291148
// Client Unexported methods
11301149
//_______________________________________________________________________

0 commit comments

Comments
 (0)