Skip to content

Commit 7c65a54

Browse files
zellynkinyoklion
andauthored
fix: use narrow local LDClient interface, not *LDClient struct (#532)
Signed-off-by: Zellyn Hunter <[email protected]> Co-authored-by: Ryan Lamb <[email protected]>
1 parent e4be360 commit 7c65a54

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

providers/launchdarkly/pkg/provider.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ import (
1212
"github.com/launchdarkly/go-sdk-common/v3/ldreason"
1313
"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
1414
"github.com/open-feature/go-sdk/openfeature"
15-
16-
ld "github.com/launchdarkly/go-server-sdk/v7"
1715
)
1816

1917
var errKeyMissing = errors.New("key and targetingKey attributes are missing, at least 1 required")
2018

2119
// Scream at compile time if Provider does not implement FeatureProvider
2220
var _ openfeature.FeatureProvider = (*Provider)(nil)
2321

22+
// LDClient is the narrowed local interface for the parts of the
23+
// `*ld.LDClient` LaunchDarkly client used by the provider.
24+
type LDClient interface {
25+
BoolVariationDetail(key string, context ldcontext.Context, defaultVal bool) (bool, ldreason.EvaluationDetail, error)
26+
IntVariationDetail(key string, context ldcontext.Context, defaultVal int) (int, ldreason.EvaluationDetail, error)
27+
Float64VariationDetail(key string, context ldcontext.Context, defaultVal float64) (float64, ldreason.EvaluationDetail, error)
28+
StringVariationDetail(key string, context ldcontext.Context, defaultVal string) (string, ldreason.EvaluationDetail, error)
29+
JSONVariationDetail(key string, context ldcontext.Context, defaultVal ldvalue.Value) (ldvalue.Value, ldreason.EvaluationDetail, error)
30+
}
31+
2432
type Option func(*options)
2533

2634
// options contains all the optional arguments supported by Provider.
@@ -47,11 +55,11 @@ func WithKindAttr(name string) Option {
4755
// Provider implements the FeatureProvider interface for LaunchDarkly.
4856
type Provider struct {
4957
options
50-
client *ld.LDClient
58+
client LDClient
5159
}
5260

5361
// NewProvider creates a new LaunchDarkly OpenFeature Provider instance.
54-
func NewProvider(ldclient *ld.LDClient, opts ...Option) *Provider {
62+
func NewProvider(ldclient LDClient, opts ...Option) *Provider {
5563
p := &Provider{
5664
client: ldclient,
5765
options: options{

0 commit comments

Comments
 (0)