From 1af316b472f5fc4140c15670ff6d9512d40980de Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Mon, 9 Sep 2024 17:27:42 +0200 Subject: [PATCH] fix: default url not picked up Signed-off-by: Fabrizio Demaria --- README.md | 5 ++--- demo/GoDemoApp.go | 3 +-- pkg/confidence/http_resolve_client.go | 2 +- pkg/confidence/models.go | 9 ++++++++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index eacd331..67b68d5 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,8 @@ require ( Below is an example for how to create a OpenFeature client using the Confidence flag provider, and then resolve a flag with a boolean attribute. -The provider is configured via `APIConfig`, with which you can set the api key for authentication. -Optionally, a custom resolve API url can be configured if, for example, the resolver service is running on -a locally deployed side-car. +The provider is configured via `NewAPIConfig(...)`, with which you can set the api key for authentication. +Optionally, a custom resolve API url can be configured if, for example, the resolver service is running on a locally deployed side-car (`NewAPIConfigWithUrl(...)`). The flag will be applied immediately, meaning that Confidence will count the targeted user as having received the treatment. diff --git a/demo/GoDemoApp.go b/demo/GoDemoApp.go index 1fcf18c..a60d678 100644 --- a/demo/GoDemoApp.go +++ b/demo/GoDemoApp.go @@ -9,7 +9,7 @@ import ( func main() { fmt.Println("Fetching the flags...") - confidence := c.NewConfidenceBuilder().SetAPIConfig(c.APIConfig{APIKey: "API_KEY"}).Build() + confidence := c.NewConfidenceBuilder().SetAPIConfig(*c.NewAPIConfig("API_KEY")).Build() targetingKey := "Random_targeting_key" confidence.PutContext("targeting_key", targetingKey) @@ -34,5 +34,4 @@ func main() { wg := confidence.Track(context.Background(), "page-viewed", map[string]interface{}{}) wg.Wait() fmt.Println("Event sent") - } diff --git a/pkg/confidence/http_resolve_client.go b/pkg/confidence/http_resolve_client.go index 775afb9..d119b87 100644 --- a/pkg/confidence/http_resolve_client.go +++ b/pkg/confidence/http_resolve_client.go @@ -34,7 +34,7 @@ func (client HttpResolveClient) SendResolveRequest(ctx context.Context, payload := bytes.NewBuffer(jsonRequest) req, err := http.NewRequestWithContext(ctx, - http.MethodPost, fmt.Sprintf("%s/flags:resolve", client.Config.APIResolveUrl), payload) + http.MethodPost, fmt.Sprintf("%s/v1/flags:resolve", client.Config.APIResolveUrl), payload) if err != nil { return ResolveResponse{}, err } diff --git a/pkg/confidence/models.go b/pkg/confidence/models.go index 09dfd9e..9b0c56c 100644 --- a/pkg/confidence/models.go +++ b/pkg/confidence/models.go @@ -64,7 +64,14 @@ type APIConfig struct { func NewAPIConfig(apiKey string) *APIConfig { return &APIConfig{ APIKey: apiKey, - APIResolveUrl: "https://resolver.confidence.dev/v1", + APIResolveUrl: "https://resolver.confidence.dev", + } +} + +func NewAPIConfigWithUrl(apiKey, apiResolveUrl string) *APIConfig { + return &APIConfig{ + APIKey: apiKey, + APIResolveUrl: apiResolveUrl, } }