-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (55 loc) · 1.35 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
62
63
64
65
66
67
68
69
package main
import (
"context"
"encoding/json"
"fmt"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
ffclient "github.com/thomaspoignant/go-feature-flag"
"github.com/thomaspoignant/go-feature-flag/ffuser"
"github.com/thomaspoignant/go-feature-flag/retriever/fileretriever"
)
type user struct {
userId string
value string
ffuser ffuser.User
}
var users [10000]user
func main() {
app := fiber.New()
// Or extend your config for customization
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowHeaders: "Origin, Content-Type, Accept",
}))
app.Static("/", "./public")
err := ffclient.Init(ffclient.Config{
PollingInterval: 500 * time.Microsecond,
Context: context.Background(),
Retriever: &fileretriever.Retriever{
Path: "flags.yaml",
},
})
for i := 0; i < 10000; i++ {
id := i
u := ffuser.NewUser(fmt.Sprint(id))
users[i].ffuser = u
}
if err != nil {
panic(err)
}
app.Get("/", func(c *fiber.Ctx) error {
var mapToRender [10000]string
for i, user := range users {
color, _ := ffclient.StringVariation("color-flag", user.ffuser, "grey")
mapToRender[i] = color
}
jsonMapToRender, err := json.Marshal(mapToRender)
if err != nil {
return c.SendStatus(fiber.StatusInternalServerError)
}
return c.SendString(string(jsonMapToRender))
})
app.Listen(":3030")
}