From 064bef291ec72a6ff3facf4a9ecc7d6377ef410d Mon Sep 17 00:00:00 2001 From: Nicklas Lundin Date: Wed, 7 Feb 2024 10:42:11 +0100 Subject: [PATCH] fix: ApiConfig constructor with region defaults (#43) * fix: fix region naming * add and use a constructor for APIConfig --- demo/GoDemoApp.go | 3 ++- pkg/provider/models.go | 19 +++++++++++++------ pkg/provider/provider_internal_test.go | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/demo/GoDemoApp.go b/demo/GoDemoApp.go index c2b2e69..0c5d7bc 100644 --- a/demo/GoDemoApp.go +++ b/demo/GoDemoApp.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "github.com/google/uuid" "github.com/open-feature/go-sdk/pkg/openfeature" confidence "github.com/spotify/confidence-openfeature-provider-go/pkg/provider" @@ -12,7 +13,7 @@ func main() { clientSecret := "CLIENT_SECRET" fmt.Println("Fetching the flags...") - provider, err := confidence.NewFlagProvider(confidence.APIConfig{APIKey: clientSecret, Region: confidence.APIRegionEU}) + provider, err := confidence.NewFlagProvider(*confidence.NewAPIConfig(clientSecret)) if err != nil { // handle error diff --git a/pkg/provider/models.go b/pkg/provider/models.go index 903760c..912704e 100644 --- a/pkg/provider/models.go +++ b/pkg/provider/models.go @@ -12,10 +12,17 @@ type APIConfig struct { Region APIRegion } +func NewAPIConfig(apiKey string) *APIConfig { + return &APIConfig{ + APIKey: apiKey, + Region: APIRegionGlobal, + } +} + const ( - APIRegionEU = iota - APIRegionUS = iota - APIRegionsGlobal = iota + APIRegionEU = iota + APIRegionUS = iota + APIRegionGlobal = iota ) // Private types below @@ -29,7 +36,7 @@ func (r APIRegion) apiURL() string { return euAPIURL } else if r == APIRegionUS { return usAPIURL - } else if r == APIRegionsGlobal { + } else if r == APIRegionGlobal { return globalAPIURL } return "" @@ -60,8 +67,8 @@ type resolveRequest struct { } type sdk struct { - Id string `json:"id"` - Version string `json:"version"` + Id string `json:"id"` + Version string `json:"version"` } type resolveResponse struct { diff --git a/pkg/provider/provider_internal_test.go b/pkg/provider/provider_internal_test.go index 90172e4..6a2ef3d 100644 --- a/pkg/provider/provider_internal_test.go +++ b/pkg/provider/provider_internal_test.go @@ -190,7 +190,7 @@ func TestResolveWithNonExistingFlag(t *testing.T) { func client(response resolveResponse, errorToReturn error) *openfeature.Client { provider := FlagProvider{Config: APIConfig{APIKey: "apikey", - Region: APIRegionsGlobal}, ResolveClient: MockResolveClient{MockedResponse: response, MockedError: errorToReturn}} + Region: APIRegionGlobal}, ResolveClient: MockResolveClient{MockedResponse: response, MockedError: errorToReturn}} openfeature.SetProvider(provider) return openfeature.NewClient("testApp") }