Skip to content

Commit

Permalink
bring back demo
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidlazio committed Sep 8, 2023
1 parent 96b495d commit e64f49b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
49 changes: 49 additions & 0 deletions demo/GoDemoApp.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
14 changes: 14 additions & 0 deletions demo/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
16 changes: 16 additions & 0 deletions demo/go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit e64f49b

Please sign in to comment.