@@ -78,49 +78,44 @@ func NewClient(apiKey string, options ...Option) *Client {
7878 }
7979 }
8080
81+ // If a resty custom client has been provided, client is already set - otherwise we use a custom http client or default to a resty
8182 if c .client == nil {
8283 if c .httpClient != nil {
8384 c .client = resty .NewWithClient (c .httpClient )
85+ c .config .userProvidedClient = true
8486 } else {
8587 c .client = resty .New ()
8688 }
87- }
88-
89- for _ , opt := range options {
90- name := getOptionQualifiedName (opt )
91- if isClientOption (name ) {
92- continue
93- }
94- opt (c )
89+ } else {
90+ c .config .userProvidedClient = true
9591 }
9692
9793 c .client .SetHeaders (map [string ]string {
9894 "Accept" : "application/json" ,
9995 EnvironmentKeyHeader : c .apiKey ,
10096 })
101- c .client .SetTimeout (c .config .timeout )
97+
98+ if c .client .GetClient ().Timeout == 0 {
99+ c .client .SetTimeout (c .config .timeout )
100+ }
101+
102102 c .log = createLogger ()
103103
104104 for _ , opt := range options {
105- if opt != nil {
106- opt (c )
105+ name := getOptionQualifiedName (opt )
106+ if isClientOption (name ) {
107+ continue
107108 }
109+ opt (c )
108110 }
109111
110- // If a resty custom client has been provided, client is already set - otherwise we use a custom http client or default to a resty
111- if c .client == nil {
112- if c .httpClient != nil {
113- c .client = resty .NewWithClient (c .httpClient )
114- } else {
115- c .client = resty .New ()
116- }
112+ if ! c .config .userProvidedClient {
113+ c .client = c .client .
114+ SetLogger (newSlogToRestyAdapter (c .log )).
115+ OnBeforeRequest (newRestyLogRequestMiddleware (c .log )).
116+ OnAfterResponse (newRestyLogResponseMiddleware (c .log ))
117117 }
118118
119- c .client = c .client .
120- SetLogger (newSlogToRestyAdapter (c .log )).
121- OnBeforeRequest (newRestyLogRequestMiddleware (c .log )).
122- OnAfterResponse (newRestyLogResponseMiddleware (c .log ))
123-
124119 c .log .Info ("initialising Flagsmith client" ,
125120 "base_url" , c .config .baseURL ,
126121 "local_evaluation" , c .config .localEvaluation ,
0 commit comments