-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (44 loc) · 1.47 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
package main
import (
"context"
"net/http"
configcat "github.com/configcat/go-sdk/v8"
"github.com/gin-gonic/gin"
provider "github.com/open-feature/go-sdk-contrib/providers/configcat/pkg"
"github.com/open-feature/go-sdk/openfeature"
)
type course struct {
ID string `json:"id"`
Title string `json:"title"`
Instructor string `json:"instructor"`
Price float64 `json:"price"`
}
var courses = []course{
{ID: "1", Title: "Intro to HTML", Instructor: "Guy Person", Price: 49.99},
{ID: "2", Title: "Intro to JavaScript", Instructor: "Mister Coder", Price: 59.99},
{ID: "3", Title: "Building APIs with Go", Instructor: "Sir Programmer", Price: 60.99},
}
func main() {
// Create the provider around ConfigCat client. Remember to replace "YOUR-SDK-KEY" with your ConfigCat SDK key
ccProvider := provider.NewProvider(configcat.NewClient("YOUR-SDK-KEY"))
// Enable the provider
openfeature.SetProvider(ccProvider)
// Create a new OpenFeature client
client := openfeature.NewClient("app")
router := gin.Default()
router.GET("/courses", func(c *gin.Context) {
// Fetch the value of the feature flag
getCoursesEnabled, _ := client.BooleanValue(
context.Background(), "get_courses_enabled", false, openfeature.EvaluationContext{},
)
if getCoursesEnabled {
c.IndentedJSON(http.StatusOK, courses)
} else {
c.IndentedJSON(http.StatusNotFound, gin.H{
"code": http.StatusNotFound,
"message": "Not Found",
})
}
})
router.Run("localhost:8000")
}