Skip to content

Commit

Permalink
fix: ApiConfig constructor with region defaults (#43)
Browse files Browse the repository at this point in the history
* fix: fix region naming

* add and use a constructor for APIConfig
  • Loading branch information
nicklasl authored Feb 7, 2024
1 parent a97d02a commit 064bef2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion demo/GoDemoApp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
19 changes: 13 additions & 6 deletions pkg/provider/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ""
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/provider_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 064bef2

Please sign in to comment.