Skip to content

Commit 593d731

Browse files
authored
feat: allow passing custom http client (#75)
1 parent 502313e commit 593d731

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

eppoclient/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package eppoclient
22

33
import (
44
"fmt"
5+
"net/http"
56
"time"
67

78
"go.uber.org/zap"
@@ -16,6 +17,7 @@ type Config struct {
1617
AssignmentLogger IAssignmentLogger
1718
PollerInterval time.Duration
1819
ApplicationLogger ApplicationLogger
20+
HttpClient *http.Client
1921
}
2022

2123
func (cfg *Config) validate() error {

eppoclient/initclient.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ func InitClient(config Config) (*EppoClient, error) {
1414
sdkParams := SDKParams{sdkKey: config.SdkKey, sdkName: "go", sdkVersion: __version__}
1515
applicationLogger := config.ApplicationLogger
1616

17-
httpClient := newHttpClient(config.BaseUrl, &http.Client{Timeout: REQUEST_TIMEOUT_SECONDS}, sdkParams)
17+
var httpClientInstance *http.Client
18+
if config.HttpClient != nil {
19+
httpClientInstance = config.HttpClient
20+
} else {
21+
httpClientInstance = &http.Client{Timeout: REQUEST_TIMEOUT_SECONDS}
22+
}
23+
httpClient := newHttpClient(config.BaseUrl, httpClientInstance, sdkParams)
1824
configStore := newConfigurationStore()
1925
requestor := newConfigurationRequestor(*httpClient, configStore, applicationLogger)
2026

0 commit comments

Comments
 (0)