Skip to content

Commit c7ddccf

Browse files
erkasahidvelji
andauthored
chore(statsig): bump minimum Go requirement to 1.24 and modernize (#770)
Signed-off-by: Roman Dmytrenko <[email protected]> Co-authored-by: Sahid Velji <[email protected]>
1 parent 966f5d2 commit c7ddccf

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

providers/statsig/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/open-feature/go-sdk-contrib/providers/statsig
22

3-
go 1.23.0
4-
5-
toolchain go1.24.4
3+
go 1.24.0
64

75
require (
86
github.com/open-feature/go-sdk v1.15.1

providers/statsig/pkg/provider.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package statsig
33
import (
44
"context"
55
"fmt"
6+
"maps"
67
"reflect"
78

89
of "github.com/open-feature/go-sdk/openfeature"
@@ -170,7 +171,7 @@ func (p *Provider) StringEvaluation(ctx context.Context, flag string, defaultVal
170171
}
171172
}
172173

173-
func (p *Provider) ObjectEvaluation(ctx context.Context, flag string, defaultValue interface{}, evalCtx of.FlattenedContext) of.InterfaceResolutionDetail {
174+
func (p *Provider) ObjectEvaluation(ctx context.Context, flag string, defaultValue any, evalCtx of.FlattenedContext) of.InterfaceResolutionDetail {
174175
// TODO to be removed on new SDK version adoption which includes https://github.com/open-feature/spec/issues/238
175176
if p.status != of.ReadyState {
176177
if p.status == of.NotReadyState {
@@ -213,8 +214,8 @@ func (p *Provider) ObjectEvaluation(ctx context.Context, flag string, defaultVal
213214
},
214215
}
215216
}
216-
var value interface{}
217-
flagMetadata := make(map[string]interface{})
217+
var value any
218+
flagMetadata := make(map[string]any)
218219
switch featureConfig.FeatureConfigType {
219220
case CONFIG:
220221
config := statsig.GetConfig(*statsigUser, featureConfig.Name)
@@ -229,10 +230,10 @@ func (p *Provider) ObjectEvaluation(ctx context.Context, flag string, defaultVal
229230
case reflect.String:
230231
value = config.GetString(flag, defaultValueV.String())
231232
case reflect.Array, reflect.Slice:
232-
sliceDefaultValue, _ := defaultValueV.Interface().([]interface{})
233+
sliceDefaultValue, _ := defaultValueV.Interface().([]any)
233234
value = config.GetSlice(flag, sliceDefaultValue)
234235
case reflect.Map:
235-
mapValue, ok := defaultValueV.Interface().(map[string]interface{})
236+
mapValue, ok := defaultValueV.Interface().(map[string]any)
236237
if !ok {
237238
return of.InterfaceResolutionDetail{
238239
Value: defaultValue,
@@ -269,10 +270,10 @@ func (p *Provider) ObjectEvaluation(ctx context.Context, flag string, defaultVal
269270
case reflect.String:
270271
value = layer.GetString(flag, defaultValueV.String())
271272
case reflect.Array, reflect.Slice:
272-
sliceDefaultValue, _ := defaultValueV.Interface().([]interface{})
273+
sliceDefaultValue, _ := defaultValueV.Interface().([]any)
273274
value = layer.GetSlice(flag, sliceDefaultValue)
274275
case reflect.Map:
275-
mapValue, ok := defaultValueV.Interface().(map[string]interface{})
276+
mapValue, ok := defaultValueV.Interface().(map[string]any)
276277
if !ok {
277278
return of.InterfaceResolutionDetail{
278279
Value: defaultValue,
@@ -365,19 +366,17 @@ func ToStatsigUser(evalCtx of.FlattenedContext) (*statsig.User, error) {
365366
}
366367
statsigUser.AppVersion = val
367368
case "Custom":
368-
if val, ok := origVal.(map[string]interface{}); ok {
369+
if val, ok := origVal.(map[string]any); ok {
369370
if statsigUser.Custom == nil {
370371
statsigUser.Custom = val
371372
} else {
372-
for k, v := range val {
373-
statsigUser.Custom[k] = v
374-
}
373+
maps.Copy(statsigUser.Custom, val)
375374
}
376375
} else {
377376
return nil, fmt.Errorf("key `%s` can not be converted to map", key)
378377
}
379378
case "PrivateAttributes":
380-
if val, ok := origVal.(map[string]interface{}); ok {
379+
if val, ok := origVal.(map[string]any); ok {
381380
statsigUser.PrivateAttributes = val
382381
} else {
383382
return nil, fmt.Errorf("key `%s` can not be converted to map", key)
@@ -397,7 +396,7 @@ func ToStatsigUser(evalCtx of.FlattenedContext) (*statsig.User, error) {
397396
case featureConfigKey:
398397
default:
399398
if statsigUser.Custom == nil {
400-
statsigUser.Custom = make(map[string]interface{})
399+
statsigUser.Custom = make(map[string]any)
401400
}
402401
statsigUser.Custom[key] = origVal
403402
}
@@ -412,7 +411,7 @@ func ToStatsigUser(evalCtx of.FlattenedContext) (*statsig.User, error) {
412411
return &statsigUser, nil
413412
}
414413

415-
func toStr(val interface{}) (string, bool) {
414+
func toStr(val any) (string, bool) {
416415
switch v := val.(type) {
417416
case string:
418417
return v, true

providers/statsig/pkg/provider_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestBooleanEvaluation(t *testing.T) {
2727

2828
evalCtx := of.NewEvaluationContext(
2929
"",
30-
map[string]interface{}{
30+
map[string]any{
3131
"UserID": "123",
3232
},
3333
)
@@ -51,7 +51,7 @@ func TestStringConfigEvaluation(t *testing.T) {
5151

5252
evalCtx := of.NewEvaluationContext(
5353
"",
54-
map[string]interface{}{
54+
map[string]any{
5555
"UserID": "123",
5656
"Email": "[email protected]",
5757
"feature_config": featureConfig,
@@ -78,7 +78,7 @@ func TestBoolLayerEvaluation(t *testing.T) {
7878

7979
evalCtx := of.NewEvaluationContext(
8080
"",
81-
map[string]interface{}{
81+
map[string]any{
8282
"UserID": "123",
8383
"feature_config": featureConfig,
8484
},
@@ -110,8 +110,8 @@ func TestConvertsValidEvaluationContextToStatsigUser(t *testing.T) {
110110
"Country": "US",
111111
"Locale": "en-US",
112112
"AppVersion": "1.0.0",
113-
"Custom": map[string]interface{}{"customKey": "customValue"},
114-
"PrivateAttributes": map[string]interface{}{"privateKey": "privateValue"},
113+
"Custom": map[string]any{"customKey": "customValue"},
114+
"PrivateAttributes": map[string]any{"privateKey": "privateValue"},
115115
"StatsigEnvironment": map[string]string{"envKey": "envValue"},
116116
"CustomIDs": map[string]string{"customIDKey": "customIDValue"},
117117
"custom-key": "custom-value",
@@ -219,26 +219,26 @@ func TestEvaluationMethods(t *testing.T) {
219219

220220
tests := []struct {
221221
flag string
222-
defaultValue interface{}
222+
defaultValue any
223223
evalCtx of.FlattenedContext
224-
expected interface{}
224+
expected any
225225
expectedError string
226226
}{
227227
{"always_on_gate", false, of.FlattenedContext{"UserID": "123"}, true, ""},
228228

229229
{"boolean", false, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "valid_flag"}}, true, ""},
230230
{"float", 1.5999, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "valid_flag"}}, 1.5, ""},
231231
{"number", int64(42999), of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "valid_flag"}}, int64(42), ""},
232-
{"object", map[string]interface{}{"key": "value999"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "valid_flag"}}, map[string]interface{}{"key1": "value1"}, ""},
232+
{"object", map[string]any{"key": "value999"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "valid_flag"}}, map[string]any{"key1": "value1"}, ""},
233233
{"string", "default_value", of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "valid_flag"}}, "expected_value", ""},
234-
{"slice", []interface{}{"fallback1", "fallback2"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "valid_flag"}}, []interface{}{"v1", "v2"}, ""},
234+
{"slice", []any{"fallback1", "fallback2"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "valid_flag"}}, []any{"v1", "v2"}, ""},
235235

236236
{"boolean", false, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "valid_layer"}}, true, ""},
237237
{"float", 1.5999, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "valid_layer"}}, 1.5, ""},
238238
{"number", int64(42999), of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "valid_layer"}}, int64(42), ""},
239-
{"object", map[string]interface{}{"key": "value999"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "valid_layer"}}, map[string]interface{}{"key1": "value1"}, ""},
239+
{"object", map[string]any{"key": "value999"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "valid_layer"}}, map[string]any{"key1": "value1"}, ""},
240240
{"string", "default_value", of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "valid_layer"}}, "expected_value", ""},
241-
{"slice", []interface{}{"fallback1", "fallback2"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "valid_layer"}}, []interface{}{"v1", "v2"}, ""},
241+
{"slice", []any{"fallback1", "fallback2"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "valid_layer"}}, []any{"v1", "v2"}, ""},
242242

243243
{"invalid_flag", false, of.FlattenedContext{"UserID": "123"}, false, "flag not found"},
244244

@@ -247,12 +247,12 @@ func TestEvaluationMethods(t *testing.T) {
247247

248248
{"float", 1.23, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "invalid_flag"}}, 1.23, "flag not found"},
249249
{"number", int64(43), of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "invalid_flag"}}, int64(43), "flag not found"},
250-
{"object", map[string]interface{}{"key1": "other-value"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "invalid_flag"}}, map[string]interface{}{"key1": "other-value"}, "flag not found"},
250+
{"object", map[string]any{"key1": "other-value"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "invalid_flag"}}, map[string]any{"key1": "other-value"}, "flag not found"},
251251
{"string", "value2", of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "CONFIG", Name: "invalid_flag"}}, "value2", "flag not found"},
252252

253253
{"float", 1.23, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "invalid_flag"}}, 1.23, "flag not found"},
254254
{"number", int64(43), of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "invalid_flag"}}, int64(43), "flag not found"},
255-
{"object", map[string]interface{}{"key1": "other-value"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "invalid_flag"}}, map[string]interface{}{"key1": "other-value"}, "flag not found"},
255+
{"object", map[string]any{"key1": "other-value"}, of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "invalid_flag"}}, map[string]any{"key1": "other-value"}, "flag not found"},
256256
{"string", "value2", of.FlattenedContext{"UserID": "123", "feature_config": statsigProvider.FeatureConfig{FeatureConfigType: "LAYER", Name: "invalid_flag"}}, "value2", "flag not found"},
257257

258258
{"invalid_user_context", false, of.FlattenedContext{"UserID": "123", "invalid": "value"}, false, ""},

0 commit comments

Comments
 (0)