Skip to content

Commit 887c5cf

Browse files
committed
refactor: remove dependency on golang.org/x/exp
The exp module does not have the same compatibility guarantees as the standard library. The fact that it stays on a pseudo-version instead of a proper semver tag, and the possibility for backwards-incompatible changes, makes depending on exp in a widely-imported library a bit risky. If a dependent of the SDK updated the version of exp they relied on, the MVS algorithm could select a version that broke the SDK's usage of exp's packages. Out of an abundance of caution, I'm trying to reduce the use of exp in our private shared libraries for this reason, and the OpenFeature SDK is our only external dependency that depends on it it. The uses are pretty small. I've replaced them with existing standard library functiosn where possible, or in one place implemented the functionality myself, since `maps.Values` is only available in the standard library from go 1.23. While in the area, I've also updated a couple of functions that are already replaceable with functions from the standard slices package. Signed-off-by: Eli Treuherz <et@arenko.group>
1 parent c2eb5af commit 887c5cf

File tree

5 files changed

+20
-48
lines changed

5 files changed

+20
-48
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/cucumber/godog v0.15.0
77
github.com/go-logr/logr v1.4.2
88
github.com/golang/mock v1.6.0
9-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
109
golang.org/x/text v0.22.0
1110
)
1211

go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
22
github.com/cucumber/gherkin/go/v26 v26.2.0 h1:EgIjePLWiPeslwIWmNQ3XHcypPsWAHoMCz/YEBKP4GI=
33
github.com/cucumber/gherkin/go/v26 v26.2.0/go.mod h1:t2GAPnB8maCT4lkHL99BDCVNzCh1d7dBhCLt150Nr/0=
4-
github.com/cucumber/godog v0.14.1 h1:HGZhcOyyfaKclHjJ+r/q93iaTJZLKYW6Tv3HkmUE6+M=
5-
github.com/cucumber/godog v0.14.1/go.mod h1:FX3rzIDybWABU4kuIXLZ/qtqEe1Ac5RdXmqvACJOces=
64
github.com/cucumber/godog v0.15.0 h1:51AL8lBXF3f0cyA5CV4TnJFCTHpgiy+1x1Hb3TtZUmo=
75
github.com/cucumber/godog v0.15.0/go.mod h1:FX3rzIDybWABU4kuIXLZ/qtqEe1Ac5RdXmqvACJOces=
86
github.com/cucumber/messages/go/v21 v21.0.1 h1:wzA0LxwjlWQYZd32VTlAVDTkW6inOFmSM+RuOwHZiMI=
@@ -53,8 +51,6 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
5351
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
5452
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5553
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
56-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
57-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
5854
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
5955
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
6056
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -69,12 +65,6 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
6965
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
7066
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7167
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
72-
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
73-
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
74-
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
75-
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
76-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
77-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
7868
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
7969
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
8070
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

openfeature/event_executor.go

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ package openfeature
22

33
import (
44
"fmt"
5+
"log/slog"
6+
"slices"
57
"sync"
68
"time"
7-
8-
"log/slog"
9-
10-
"golang.org/x/exp/maps"
119
)
1210

1311
const defaultDomain = ""
@@ -260,7 +258,7 @@ func (e *eventExecutor) startListeningAndShutdownOld(newProvider providerReferen
260258
// shutdown old provider handling
261259

262260
// check if this provider is still bound - 1:N binding capability
263-
if isBound(oldReference, e.defaultProviderReference, maps.Values(e.namedProviderReference)) {
261+
if isBound(oldReference, e.defaultProviderReference, mapValues(e.namedProviderReference)) {
264262
return nil
265263
}
266264

@@ -360,26 +358,22 @@ func (e *eventExecutor) executeHandler(f func(details EventDetails), event Event
360358
}()
361359
}
362360

363-
// isRunning is a helper till we bump to the latest go version with slices.contains support
364-
func isRunning(provider providerReference, activeProviders []providerReference) bool {
365-
for _, activeProvider := range activeProviders {
366-
if activeProvider.equals(provider) {
367-
return true
368-
}
361+
// mapValues is a helper until we bump to a go version with maps.Values and slices.Collect
362+
func mapValues[K comparable, V any](m map[K]V) []V {
363+
var values []V
364+
for _, value := range m {
365+
values = append(values, value)
369366
}
370-
return false
367+
return values
371368
}
372369

373-
// isRunning is a helper to check if given provider is already in use
374-
func isBound(provider providerReference, defaultProvider providerReference, namedProviders []providerReference) bool {
375-
if provider.equals(defaultProvider) {
376-
return true
377-
}
370+
// isRunning is a helper to check if the given provider is in the given list of providers
371+
func isRunning(provider providerReference, activeProviders []providerReference) bool {
372+
return slices.ContainsFunc(activeProviders, provider.equals)
373+
}
378374

379-
for _, namedProvider := range namedProviders {
380-
if provider.equals(namedProvider) {
381-
return true
382-
}
383-
}
384-
return false
375+
// isBound is a helper to check if given provider is in the given provider or list of providers
376+
func isBound(provider providerReference, defaultProvider providerReference, namedProviders []providerReference) bool {
377+
return provider.equals(defaultProvider) ||
378+
slices.ContainsFunc(namedProviders, provider.equals)
385379
}

openfeature/event_executor_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package openfeature
33
import (
44
"errors"
55
"reflect"
6+
"slices"
67
"testing"
78
"time"
8-
9-
"golang.org/x/exp/slices"
109
)
1110

1211
func init() {

openfeature/openfeature_api.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package openfeature
33
import (
44
"errors"
55
"fmt"
6+
"slices"
67
"sync"
78

89
"github.com/go-logr/logr"
9-
"golang.org/x/exp/maps"
1010
)
1111

1212
// evaluationAPI wraps OpenFeature evaluation API functionalities
@@ -234,7 +234,7 @@ func (api *evaluationAPI) initNewAndShutdownOld(clientName string, newProvider F
234234
}
235235

236236
// check for multiple bindings
237-
if oldProvider == api.defaultProvider || contains(oldProvider, maps.Values(api.namedProviders)) {
237+
if oldProvider == api.defaultProvider || slices.Contains(mapValues(api.namedProviders), oldProvider) {
238238
return nil
239239
}
240240

@@ -278,16 +278,6 @@ func initializer(provider FeatureProvider, apiCtx EvaluationContext) (Event, err
278278
return event, err
279279
}
280280

281-
func contains(provider FeatureProvider, in []FeatureProvider) bool {
282-
for _, p := range in {
283-
if provider == p {
284-
return true
285-
}
286-
}
287-
288-
return false
289-
}
290-
291281
var statesMap = map[EventType]func(ProviderEventDetails) State{
292282
ProviderReady: func(_ ProviderEventDetails) State { return ReadyState },
293283
ProviderConfigChange: func(_ ProviderEventDetails) State { return ReadyState },

0 commit comments

Comments
 (0)