diff --git a/README.md b/README.md index e17bc03..140f680 100644 --- a/README.md +++ b/README.md @@ -57,4 +57,4 @@ boolValue, error := client.BooleanValue(context.Background(), "test-flag.boolean To run the demo app, replace the `CLIENT_SECRET` with client secret setup in the [Confidence](https://confidence.spotify.com/) console, the flags with existing flags and execute -the app with `go run pkg/demo/GoDemoApp.go`. +the app with `cd demo && go run GoDemoApp.go`. diff --git a/demo/GoDemoApp.go b/demo/GoDemoApp.go new file mode 100644 index 0000000..c2b2e69 --- /dev/null +++ b/demo/GoDemoApp.go @@ -0,0 +1,49 @@ +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" +) + +func main() { + clientSecret := "CLIENT_SECRET" + fmt.Println("Fetching the flags...") + + provider, err := confidence.NewFlagProvider(confidence.APIConfig{APIKey: clientSecret, Region: confidence.APIRegionEU}) + + if err != nil { + // handle error + } + + openfeature.SetProvider(provider) + client := openfeature.NewClient("testApp") + + attributes := make(map[string]interface{}) + targetingKey := uuid.New().String() + attributes["targeting_key"] = targetingKey + + fmt.Println(" Random UUID -> " + targetingKey) + + of := openfeature.NewEvaluationContext("", attributes) + + colorValue, _ := client.StringValue(context.Background(), "hawkflag.color", "defaultValue", of) + messageValue, _ := client.StringValue(context.Background(), "hawkflag.message", "defaultValue", of) + + colorYellow := "\033[33m" + colorGreen := "\033[32m" + colorRed := "\033[31m" + + fmt.Println(" Color --> " + colorValue) + + switch { + case colorValue == "Yellow": + fmt.Println(colorYellow, "Message --> "+messageValue) + case colorValue == "Green": + fmt.Println(colorGreen, "Message --> "+messageValue) + default: + fmt.Println(colorRed, "Message --> "+messageValue) + } +} diff --git a/demo/go.mod b/demo/go.mod new file mode 100644 index 0000000..792c303 --- /dev/null +++ b/demo/go.mod @@ -0,0 +1,14 @@ +module demo + +go 1.19 + +require ( + github.com/google/uuid v1.3.1 + github.com/open-feature/go-sdk v1.7.0 + github.com/spotify/confidence-openfeature-provider-go v0.1.3 +) + +require ( + github.com/go-logr/logr v1.2.4 // indirect + golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect +) diff --git a/demo/go.sum b/demo/go.sum new file mode 100644 index 0000000..3814d6f --- /dev/null +++ b/demo/go.sum @@ -0,0 +1,16 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/open-feature/go-sdk v1.7.0 h1:g6o/sf5xaED7xawXwZ0LqE7RS9co7HZJMClXCXmIbgw= +github.com/open-feature/go-sdk v1.7.0/go.mod h1:5aV26tEoQuompRa8A6BAGukhi88pRMZsslJJwucGNzs= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/spotify/confidence-openfeature-provider-go v0.1.3 h1:C9kxRqGDV67bZX8VR2Q0JbtJgsa5sdBPueWPldmtQ2g= +github.com/spotify/confidence-openfeature-provider-go v0.1.3/go.mod h1://Zd5cb0T5/dATOKWLuul24pKxMfTwQiTFJ8Fjfk4Ts= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= +golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=