-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 1.33 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"github.com/gin-gonic/gin"
gofeatureflag "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/pkg"
"github.com/open-feature/go-sdk/pkg/openfeature"
"google.golang.org/appengine/log"
"net/http"
"time"
)
const defaultMessage = "Hello!"
const newWelcomeMessage = "Hello, welcome to this OpenFeature-enabled website!"
func main() {
// Initialize Go Gin
engine := gin.Default()
// Setup a simple endpoint
engine.GET("/hello", func(c *gin.Context) {
options := gofeatureflag.ProviderOptions{
Endpoint: "http://localhost:1031",
HTTPClient: &http.Client{
Timeout: 1 * time.Second,
},
}
provider, _ := gofeatureflag.NewProvider(options)
openfeature.SetProvider(provider)
client := openfeature.NewClient("demo")
evaluationCtx := openfeature.NewEvaluationContext(
"test",
map[string]interface{}{
"firstname": "mark",
"lastname": "",
"email": "[email protected]",
"admin": true,
"anonymous": false,
})
welcomeMessage, err := client.BooleanValue(context.Background(), "test-flag", false, evaluationCtx)
if err != nil {
log.Errorf(context.Background(), err.Error())
return
}
if welcomeMessage {
c.JSON(http.StatusOK, newWelcomeMessage)
return
} else {
c.JSON(http.StatusOK, defaultMessage)
return
}
})
engine.Run()
}