@@ -19,6 +19,9 @@ var errKeyMissing = errors.New("key and targetingKey attributes are missing, at
1919// Scream at compile time if Provider does not implement FeatureProvider
2020var _ openfeature.FeatureProvider = (* Provider )(nil )
2121
22+ // Scream at compile time if Provider does not implement StateHandler
23+ var _ openfeature.StateHandler = (* Provider )(nil )
24+
2225// LDClient is the narrowed local interface for the parts of the
2326// `*ld.LDClient` LaunchDarkly client used by the provider.
2427type LDClient interface {
@@ -27,14 +30,16 @@ type LDClient interface {
2730 Float64VariationDetail (key string , context ldcontext.Context , defaultVal float64 ) (float64 , ldreason.EvaluationDetail , error )
2831 StringVariationDetail (key string , context ldcontext.Context , defaultVal string ) (string , ldreason.EvaluationDetail , error )
2932 JSONVariationDetail (key string , context ldcontext.Context , defaultVal ldvalue.Value ) (ldvalue.Value , ldreason.EvaluationDetail , error )
33+ Close () error
3034}
3135
3236type Option func (* options )
3337
3438// options contains all the optional arguments supported by Provider.
3539type options struct {
36- kindAttr string
37- l Logger
40+ kindAttr string
41+ l Logger
42+ closeOnShutdown bool
3843}
3944
4045// WithLogger sets a logger implementation. By default a noop logger is used.
@@ -52,6 +57,14 @@ func WithKindAttr(name string) Option {
5257 }
5358}
5459
60+ // WithCloseOnShutdown sets whether the LaunchDarkly client should be closed
61+ // when the provider is shut down. By default, this is false.
62+ func WithCloseOnShutdown (close bool ) Option {
63+ return func (o * options ) {
64+ o .closeOnShutdown = close
65+ }
66+ }
67+
5568// Provider implements the FeatureProvider interface for LaunchDarkly.
5669type Provider struct {
5770 options
@@ -372,3 +385,15 @@ func (p *Provider) ObjectEvaluation(ctx context.Context, flagKey string, default
372385func (p * Provider ) Hooks () []openfeature.Hook {
373386 return []openfeature.Hook {}
374387}
388+
389+ func (p * Provider ) Init (evaluationContext openfeature.EvaluationContext ) error {
390+ return nil
391+ }
392+
393+ func (p * Provider ) Shutdown () {
394+ if p .closeOnShutdown {
395+ if err := p .client .Close (); err != nil {
396+ p .l .Error ("error during LaunchDarkly client shutdown: %s" , err )
397+ }
398+ }
399+ }
0 commit comments