File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,19 @@ func WithGitpodProxy(gitpodHost string) ClientOpt {
49
49
}
50
50
}
51
51
52
+ func WithDefaultClient (defaultClient Client ) ClientOpt {
53
+ return func (o * options ) {
54
+ o .defaultClient = defaultClient
55
+ o .hasDefaultClient = true
56
+ }
57
+ }
58
+
52
59
type options struct {
53
- pollInterval time.Duration
54
- baseURL string
55
- sdkKey string
60
+ pollInterval time.Duration
61
+ baseURL string
62
+ sdkKey string
63
+ defaultClient Client
64
+ hasDefaultClient bool
56
65
}
57
66
58
67
// NewClient constructs a new experiments.Client. This is NOT A SINGLETON.
@@ -70,6 +79,9 @@ func NewClient(opts ...ClientOpt) Client {
70
79
}
71
80
72
81
if opt .sdkKey == "" {
82
+ if opt .hasDefaultClient {
83
+ return opt .defaultClient
84
+ }
73
85
return NewAlwaysReturningDefaultValueClient ()
74
86
}
75
87
logger := log .Log .Dup ()
Original file line number Diff line number Diff line change @@ -148,8 +148,7 @@ func init() {
148
148
func startWaitFeatureFlag (ctx context.Context , timeout time.Duration ) {
149
149
featureFlagCtx , cancel := context .WithTimeout (ctx , timeout )
150
150
defer cancel ()
151
- client := experiments .NewClient ()
152
-
151
+ client := experiments .NewClient (experiments .WithDefaultClient (nil ))
153
152
defaultSkip := true
154
153
if client == nil {
155
154
log .Error ("failed to create experiments client, skip immediately" )
You can’t perform that action at this time.
0 commit comments