-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
41 lines (33 loc) · 907 Bytes
/
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
package main
import (
"context"
"log/slog"
"net/http"
"go.flipt.io/flipt/gitops-guide/pkg/server"
_ "go.flipt.io/flipt/rpc/flipt"
_ "go.flipt.io/flipt/rpc/flipt/evaluation"
sdk "go.flipt.io/flipt/sdk/go"
flipthttp "go.flipt.io/flipt/sdk/go/http"
)
func main() {
t := flipthttp.NewTransport("http://localhost:8080")
s := server.NewServer(sdk.New(t))
http.HandleFunc("/words", threadUserContext(s.ListWords))
slog.Info("Listening", "port", "8000")
http.ListenAndServe(":8000", nil)
}
func threadUserContext(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
user := r.URL.Query().Get("user")
if user == "" {
user = "default"
}
org := r.URL.Query().Get("org")
if org == "" {
org = "default"
}
ctx := context.WithValue(r.Context(), "user", user)
ctx = context.WithValue(ctx, "org", org)
next(w, r.WithContext(ctx))
}
}