Clone returns a copy of the client with the same configuration and services. The returned client has its own http.Client but shares the client configuration such as transport and timeout. The returned client starts with the same rate limit information as the original client, but it is not updated wh
(opts ...ClientOptionsFunc)
| 713 | // The returned client is independent of the original client and can be |
| 714 | // modified without affecting the original client. |
| 715 | func (c *Client) Clone(opts ...ClientOptionsFunc) (*Client, error) { |
| 716 | if c.client == nil { |
| 717 | return nil, errUninitialized |
| 718 | } |
| 719 | |
| 720 | o := clientOptions{ |
| 721 | userAgent: &c.userAgent, |
| 722 | baseURL: Ptr(*c.baseURL), |
| 723 | uploadURL: Ptr(*c.uploadURL), |
| 724 | disableRateLimitCheck: c.disableRateLimitCheck, |
| 725 | rateLimitRedirectionalEndpoints: c.rateLimitRedirectionalEndpoints, |
| 726 | maxSecondaryRateLimitRetryAfterDuration: &c.maxSecondaryRateLimitRetryAfterDuration, |
| 727 | } |
| 728 | |
| 729 | if c.Marketplace != nil { |
| 730 | o.marketplaceStubbed = c.Marketplace.Stubbed |
| 731 | } |
| 732 | |
| 733 | for _, opt := range opts { |
| 734 | if err := opt(&o); err != nil { |
| 735 | return nil, err |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | if o.httpClient == nil { |
| 740 | o.httpClient = &http.Client{ |
| 741 | Transport: c.client.Transport, |
| 742 | CheckRedirect: c.client.CheckRedirect, |
| 743 | Jar: c.client.Jar, |
| 744 | Timeout: c.client.Timeout, |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | clone, err := newClient(o) |
| 749 | if err != nil { |
| 750 | return nil, err |
| 751 | } |
| 752 | |
| 753 | if !clone.disableRateLimitCheck { |
| 754 | c.rateMu.Lock() |
| 755 | clone.rateLimits = c.rateLimits |
| 756 | clone.secondaryRateLimitReset = c.secondaryRateLimitReset |
| 757 | c.rateMu.Unlock() |
| 758 | } |
| 759 | |
| 760 | return clone, nil |
| 761 | } |
| 762 | |
| 763 | // RequestOption represents an option that can modify an http.Request. |
| 764 | type RequestOption func(req *http.Request) |