Skip to content

Commit 39251ac

Browse files
authored
chore(ofrep): bump minimum Go requirement to 1.24 and modernize (open-feature#745)
Signed-off-by: Roman Dmytrenko <[email protected]>
1 parent d0e86d0 commit 39251ac

File tree

10 files changed

+62
-69
lines changed

10 files changed

+62
-69
lines changed

providers/ofrep/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Package ofrep provides a [OpenFeature Provider] for interacting with the [OFREP] service using the [OpenFeature Go SDK].
2+
//
3+
// [OFREP]: https://github.com/open-feature/protocol
4+
// [OpenFeature Provider]: https://docs.openfeature.dev/docs/specification/sections/providers
5+
// [OpenFeature Go SDK]: https://github.com/open-feature/go-sdk
6+
package ofrep

providers/ofrep/evaluate.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
// Evaluator contract for flag evaluation
1010
type Evaluator interface {
1111
ResolveBoolean(ctx context.Context, key string, defaultValue bool,
12-
evalCtx map[string]interface{}) of.BoolResolutionDetail
12+
evalCtx map[string]any) of.BoolResolutionDetail
1313
ResolveString(ctx context.Context, key string, defaultValue string,
14-
evalCtx map[string]interface{}) of.StringResolutionDetail
14+
evalCtx map[string]any) of.StringResolutionDetail
1515
ResolveFloat(ctx context.Context, key string, defaultValue float64,
16-
evalCtx map[string]interface{}) of.FloatResolutionDetail
16+
evalCtx map[string]any) of.FloatResolutionDetail
1717
ResolveInt(ctx context.Context, key string, defaultValue int64,
18-
evalCtx map[string]interface{}) of.IntResolutionDetail
19-
ResolveObject(ctx context.Context, key string, defaultValue interface{},
20-
evalCtx map[string]interface{}) of.InterfaceResolutionDetail
18+
evalCtx map[string]any) of.IntResolutionDetail
19+
ResolveObject(ctx context.Context, key string, defaultValue any,
20+
evalCtx map[string]any) of.InterfaceResolutionDetail
2121
}

providers/ofrep/go.mod

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

3-
go 1.23.0
3+
go 1.24.0
44

55
require github.com/open-feature/go-sdk v1.15.1
66

providers/ofrep/go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
22
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
3-
github.com/open-feature/go-sdk v1.15.0 h1:FEZl4kCH6H2drhnQ0dheDBxLvwwzO7zvzdUl8zzZLX4=
4-
github.com/open-feature/go-sdk v1.15.0/go.mod h1:LkqPL/17XMGcRvTdk1qqwSSG1ICe/D2MQP0blDaXfh0=
53
github.com/open-feature/go-sdk v1.15.1 h1:TC3FtHtOKlGlIbSf3SEpxXVhgTd/bCbuc39XHIyltkw=
64
github.com/open-feature/go-sdk v1.15.1/go.mod h1:2WAFYzt8rLYavcubpCoiym3iSCXiHdPB6DxtMkv2wyo=
75
go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko=
86
go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o=
9-
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
10-
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
7+
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
8+
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=

providers/ofrep/internal/evaluate/flags.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Flags struct {
1414
}
1515

1616
type resolver interface {
17-
resolveSingle(ctx context.Context, key string, evalCtx map[string]interface{}) (*successDto, *of.ResolutionError)
17+
resolveSingle(ctx context.Context, key string, evalCtx map[string]any) (*successDto, *of.ResolutionError)
1818
}
1919

2020
func NewFlagsEvaluator(cfg outbound.Configuration) *Flags {
@@ -23,7 +23,7 @@ func NewFlagsEvaluator(cfg outbound.Configuration) *Flags {
2323
}
2424
}
2525

26-
func (h Flags) ResolveBoolean(ctx context.Context, key string, defaultValue bool, evalCtx map[string]interface{}) of.BoolResolutionDetail {
26+
func (h Flags) ResolveBoolean(ctx context.Context, key string, defaultValue bool, evalCtx map[string]any) of.BoolResolutionDetail {
2727
evalSuccess, resolutionError := h.resolver.resolveSingle(ctx, key, evalCtx)
2828
if resolutionError != nil {
2929
return of.BoolResolutionDetail{
@@ -68,7 +68,7 @@ func (h Flags) ResolveBoolean(ctx context.Context, key string, defaultValue bool
6868
}
6969
}
7070

71-
func (h Flags) ResolveString(ctx context.Context, key string, defaultValue string, evalCtx map[string]interface{}) of.StringResolutionDetail {
71+
func (h Flags) ResolveString(ctx context.Context, key string, defaultValue string, evalCtx map[string]any) of.StringResolutionDetail {
7272
evalSuccess, resolutionError := h.resolver.resolveSingle(ctx, key, evalCtx)
7373
if resolutionError != nil {
7474
return of.StringResolutionDetail{
@@ -113,7 +113,7 @@ func (h Flags) ResolveString(ctx context.Context, key string, defaultValue strin
113113
}
114114
}
115115

116-
func (h Flags) ResolveFloat(ctx context.Context, key string, defaultValue float64, evalCtx map[string]interface{}) of.FloatResolutionDetail {
116+
func (h Flags) ResolveFloat(ctx context.Context, key string, defaultValue float64, evalCtx map[string]any) of.FloatResolutionDetail {
117117
evalSuccess, resolutionError := h.resolver.resolveSingle(ctx, key, evalCtx)
118118
if resolutionError != nil {
119119
return of.FloatResolutionDetail{
@@ -164,7 +164,7 @@ func (h Flags) ResolveFloat(ctx context.Context, key string, defaultValue float6
164164
}
165165
}
166166

167-
func (h Flags) ResolveInt(ctx context.Context, key string, defaultValue int64, evalCtx map[string]interface{}) of.IntResolutionDetail {
167+
func (h Flags) ResolveInt(ctx context.Context, key string, defaultValue int64, evalCtx map[string]any) of.IntResolutionDetail {
168168
evalSuccess, resolutionError := h.resolver.resolveSingle(ctx, key, evalCtx)
169169
if resolutionError != nil {
170170
return of.IntResolutionDetail{
@@ -227,7 +227,7 @@ func (h Flags) ResolveInt(ctx context.Context, key string, defaultValue int64, e
227227
}
228228
}
229229

230-
func (h Flags) ResolveObject(ctx context.Context, key string, defaultValue interface{}, evalCtx map[string]interface{}) of.InterfaceResolutionDetail {
230+
func (h Flags) ResolveObject(ctx context.Context, key string, defaultValue any, evalCtx map[string]any) of.InterfaceResolutionDetail {
231231
evalSuccess, resolutionError := h.resolver.resolveSingle(ctx, key, evalCtx)
232232
if resolutionError != nil {
233233
return of.InterfaceResolutionDetail{

providers/ofrep/internal/evaluate/flags_test.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ type mockResolver struct {
1313
err *of.ResolutionError
1414
}
1515

16-
func (m mockResolver) resolveSingle(ctx context.Context, key string, evalCtx map[string]interface{}) (*successDto, *of.ResolutionError) {
16+
func (m mockResolver) resolveSingle(ctx context.Context, key string, evalCtx map[string]any) (*successDto, *of.ResolutionError) {
1717
return m.success, m.err
1818
}
1919

2020
type knownTypes interface {
21-
int64 | bool | float64 | string | interface{}
21+
int64 | bool | float64 | string | any
2222
}
2323

2424
type testDefinition[T knownTypes] struct {
@@ -96,8 +96,6 @@ var successObject = successDto{
9696
var parseError = of.NewParseErrorResolutionError("flag parsing error")
9797

9898
func TestBooleanEvaluation(t *testing.T) {
99-
ctx := context.Background()
100-
10199
tests := []testDefinition[bool]{
102100
{
103101
name: "Success evaluation",
@@ -139,8 +137,8 @@ func TestBooleanEvaluation(t *testing.T) {
139137
for _, test := range tests {
140138
t.Run(test.name, func(t *testing.T) {
141139
flags := Flags{resolver: test.resolver}
142-
resolutionDetail := flags.ResolveBoolean(ctx, "booleanFlag", test.defaultValue, nil)
143-
genericValidator[bool](test, resolutionDetail.Value, resolutionDetail.Reason, resolutionDetail.Error(), t)
140+
resolutionDetail := flags.ResolveBoolean(t.Context(), "booleanFlag", test.defaultValue, nil)
141+
genericValidator(test, resolutionDetail.Value, resolutionDetail.Reason, resolutionDetail.Error(), t)
144142
})
145143
}
146144
}
@@ -212,8 +210,6 @@ func TestIntegerEvaluation(t *testing.T) {
212210
}
213211

214212
func TestFloatEvaluation(t *testing.T) {
215-
ctx := context.Background()
216-
217213
tests := []testDefinition[float64]{
218214
{
219215
name: "Success evaluation",
@@ -263,15 +259,13 @@ func TestFloatEvaluation(t *testing.T) {
263259
for _, test := range tests {
264260
t.Run(test.name, func(t *testing.T) {
265261
flags := Flags{resolver: test.resolver}
266-
resolutionDetail := flags.ResolveFloat(ctx, "floatFlag", test.defaultValue, nil)
267-
genericValidator[float64](test, resolutionDetail.Value, resolutionDetail.Reason, resolutionDetail.Error(), t)
262+
resolutionDetail := flags.ResolveFloat(t.Context(), "floatFlag", test.defaultValue, nil)
263+
genericValidator(test, resolutionDetail.Value, resolutionDetail.Reason, resolutionDetail.Error(), t)
268264
})
269265
}
270266
}
271267

272268
func TestStringEvaluation(t *testing.T) {
273-
ctx := context.Background()
274-
275269
tests := []testDefinition[string]{
276270
{
277271
name: "Success evaluation",
@@ -313,22 +307,20 @@ func TestStringEvaluation(t *testing.T) {
313307
for _, test := range tests {
314308
t.Run(test.name, func(t *testing.T) {
315309
flags := Flags{resolver: test.resolver}
316-
resolutionDetail := flags.ResolveString(ctx, "stringFlag", test.defaultValue, nil)
317-
genericValidator[string](test, resolutionDetail.Value, resolutionDetail.Reason, resolutionDetail.Error(), t)
310+
resolutionDetail := flags.ResolveString(t.Context(), "stringFlag", test.defaultValue, nil)
311+
genericValidator(test, resolutionDetail.Value, resolutionDetail.Reason, resolutionDetail.Error(), t)
318312
})
319313
}
320314
}
321315

322316
func TestObjectEvaluation(t *testing.T) {
323-
ctx := context.Background()
324-
325-
tests := []testDefinition[interface{}]{
317+
tests := []testDefinition[any]{
326318
{
327319
name: "Success evaluation",
328320
resolver: mockResolver{
329321
success: &successObject,
330322
},
331-
defaultValue: map[string]interface{}{},
323+
defaultValue: map[string]any{},
332324
expect: successObject.Value,
333325
},
334326
{
@@ -337,25 +329,25 @@ func TestObjectEvaluation(t *testing.T) {
337329
err: &parseError,
338330
},
339331
isError: true,
340-
defaultValue: map[string]interface{}{},
341-
expect: map[string]interface{}{},
332+
defaultValue: map[string]any{},
333+
expect: map[string]any{},
342334
},
343335
{
344336
name: "disabled flag",
345337
resolver: mockResolver{
346338
success: &successDisabled,
347339
},
348-
defaultValue: map[string]interface{}{},
349-
expect: map[string]interface{}{},
340+
defaultValue: map[string]any{},
341+
expect: map[string]any{},
350342
isError: false,
351343
},
352344
}
353345

354346
for _, test := range tests {
355347
t.Run(test.name, func(t *testing.T) {
356348
flags := Flags{resolver: test.resolver}
357-
resolutionDetail := flags.ResolveObject(ctx, "objectFlag", test.defaultValue, nil)
358-
genericValidator[interface{}](test, resolutionDetail.Value, resolutionDetail.Reason, resolutionDetail.Error(), t)
349+
resolutionDetail := flags.ResolveObject(t.Context(), "objectFlag", test.defaultValue, nil)
350+
genericValidator(test, resolutionDetail.Value, resolutionDetail.Reason, resolutionDetail.Error(), t)
359351
})
360352
}
361353
}

providers/ofrep/internal/evaluate/resolver.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ func NewOutboundResolver(cfg outbound.Configuration) *OutboundResolver {
2828
return &OutboundResolver{client: outbound.NewHttp(cfg)}
2929
}
3030

31-
func (g *OutboundResolver) resolveSingle(ctx context.Context, key string, evalCtx map[string]interface{}) (
32-
*successDto, *of.ResolutionError) {
33-
31+
func (g *OutboundResolver) resolveSingle(ctx context.Context, key string, evalCtx map[string]any) (*successDto, *of.ResolutionError) {
3432
b, err := json.Marshal(requestFrom(evalCtx))
3533
if err != nil {
3634
resErr := of.NewGeneralResolutionError(fmt.Sprintf("context marshelling error: %v", err))
@@ -140,10 +138,10 @@ func parseError500(data []byte) *of.ResolutionError {
140138
// DTOs and OFREP models
141139

142140
type successDto struct {
143-
Value interface{}
141+
Value any
144142
Reason string
145143
Variant string
146-
Metadata map[string]interface{}
144+
Metadata map[string]any
147145
}
148146

149147
func toSuccessDto(e evaluationSuccess) (*successDto, *of.ResolutionError) {
@@ -154,7 +152,7 @@ func toSuccessDto(e evaluationSuccess) (*successDto, *of.ResolutionError) {
154152
}
155153

156154
if e.Metadata != nil {
157-
m, ok := e.Metadata.(map[string]interface{})
155+
m, ok := e.Metadata.(map[string]any)
158156
if !ok {
159157
resErr := of.NewParseErrorResolutionError("metadata must be a map of string keys and arbitrary values")
160158
return nil, &resErr
@@ -165,21 +163,21 @@ func toSuccessDto(e evaluationSuccess) (*successDto, *of.ResolutionError) {
165163
}
166164

167165
type request struct {
168-
Context interface{} `json:"context"`
166+
Context any `json:"context"`
169167
}
170168

171-
func requestFrom(ctx map[string]interface{}) request {
169+
func requestFrom(ctx map[string]any) request {
172170
return request{
173171
Context: ctx,
174172
}
175173
}
176174

177175
type evaluationSuccess struct {
178-
Value interface{} `json:"value"`
179-
Key string `json:"key"`
180-
Reason string `json:"reason"`
181-
Variant string `json:"variant"`
182-
Metadata interface{} `json:"metadata"`
176+
Value any `json:"value"`
177+
Key string `json:"key"`
178+
Reason string `json:"reason"`
179+
Variant string `json:"variant"`
180+
Metadata any `json:"metadata"`
183181
}
184182

185183
type evaluationError struct {

providers/ofrep/internal/evaluate/resolver_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var success = evaluationSuccess{
2222
Key: "flagA",
2323
Reason: string(of.StaticReason),
2424
Variant: "true",
25-
Metadata: map[string]interface{}{
25+
Metadata: map[string]any{
2626
"key": "value",
2727
},
2828
}
@@ -56,7 +56,7 @@ func TestSuccess200(t *testing.T) {
5656
},
5757
}}
5858

59-
successDto, resolutionError := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
59+
successDto, resolutionError := resolver.resolveSingle(t.Context(), "", make(map[string]any))
6060

6161
if resolutionError != nil {
6262
t.Errorf("expected no errors, but got error: %v", err)
@@ -90,7 +90,7 @@ func TestSuccess200(t *testing.T) {
9090
Data: []byte("some payload"),
9191
},
9292
}}
93-
success, resolutionError := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
93+
success, resolutionError := resolver.resolveSingle(t.Context(), "", make(map[string]any))
9494

9595
validateErrorCode(success, resolutionError, of.ParseErrorCode, t)
9696
})
@@ -107,7 +107,7 @@ func TestSuccess200(t *testing.T) {
107107
Data: b,
108108
},
109109
}}
110-
success, resolutionError := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
110+
success, resolutionError := resolver.resolveSingle(t.Context(), "", make(map[string]any))
111111

112112
validateErrorCode(success, resolutionError, of.ParseErrorCode, t)
113113
})
@@ -123,7 +123,7 @@ func TestSuccess200(t *testing.T) {
123123
Data: b,
124124
},
125125
}}
126-
success, _ := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
126+
success, _ := resolver.resolveSingle(t.Context(), "", make(map[string]any))
127127

128128
if len(success.Metadata) > 0 {
129129
t.Errorf("should not have metadata, but got %v", success.Metadata)
@@ -169,7 +169,7 @@ func TestResolveGeneralErrors(t *testing.T) {
169169
for _, test := range tests {
170170
t.Run(test.name, func(t *testing.T) {
171171
resolver := OutboundResolver{client: test.client}
172-
success, resolutionError := resolver.resolveSingle(context.Background(), "key", map[string]interface{}{})
172+
success, resolutionError := resolver.resolveSingle(t.Context(), "key", map[string]any{})
173173

174174
validateErrorCode(success, resolutionError, of.GeneralCode, t)
175175
})
@@ -225,7 +225,7 @@ func TestEvaluationError4xx(t *testing.T) {
225225
Data: errBytes,
226226
},
227227
}}
228-
success, resolutionError := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
228+
success, resolutionError := resolver.resolveSingle(t.Context(), "", make(map[string]any))
229229

230230
validateErrorCode(success, resolutionError, test.expectCode, t)
231231
})
@@ -238,7 +238,7 @@ func TestFlagNotFound404(t *testing.T) {
238238
Status: http.StatusNotFound,
239239
},
240240
}}
241-
success, resolutionError := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
241+
success, resolutionError := resolver.resolveSingle(t.Context(), "", make(map[string]any))
242242

243243
validateErrorCode(success, resolutionError, of.FlagNotFoundCode, t)
244244
}
@@ -275,7 +275,7 @@ func Test429(t *testing.T) {
275275
}
276276

277277
resolver := OutboundResolver{client: mockOutbound{rsp: response}}
278-
success, resolutionError := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
278+
success, resolutionError := resolver.resolveSingle(t.Context(), "", make(map[string]any))
279279

280280
validateErrorCode(success, resolutionError, of.GeneralCode, t)
281281
})
@@ -290,7 +290,7 @@ func TestEvaluationError5xx(t *testing.T) {
290290
Data: []byte{},
291291
},
292292
}}
293-
success, resolutionError := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
293+
success, resolutionError := resolver.resolveSingle(t.Context(), "", make(map[string]any))
294294

295295
validateErrorCode(success, resolutionError, of.GeneralCode, t)
296296
})
@@ -307,7 +307,7 @@ func TestEvaluationError5xx(t *testing.T) {
307307
Data: errorBytes,
308308
},
309309
}}
310-
success, resolutionError := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
310+
success, resolutionError := resolver.resolveSingle(t.Context(), "", make(map[string]any))
311311

312312
validateErrorCode(success, resolutionError, of.GeneralCode, t)
313313
})
@@ -319,7 +319,7 @@ func TestEvaluationError5xx(t *testing.T) {
319319
Data: []byte("some error"),
320320
},
321321
}}
322-
success, resolutionError := resolver.resolveSingle(context.Background(), "", make(map[string]interface{}))
322+
success, resolutionError := resolver.resolveSingle(t.Context(), "", make(map[string]any))
323323

324324
validateErrorCode(success, resolutionError, of.GeneralCode, t)
325325
})

0 commit comments

Comments
 (0)