Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit ab16700

Browse files
author
Thomas Poignant
committed
Init repo
0 parents  commit ab16700

12 files changed

+3513
-0
lines changed

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories
15+
vendor/
16+
17+
# IDE
18+
.DS_Store
19+
.vscode
20+
.idea
21+
*.iml
22+
.run
23+
24+
# reporting stuff
25+
*-report.xml
26+
*.cov
27+
coverage.xml
28+
bin/
29+
out/
30+
tmp/

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Thomas Poignant
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# GO Feature Flag demo
2+
3+
This repository contains a demo app which display a webapp containing a grid of users.
4+
Each square is a different user.
5+
6+
With this demo app you can modify your flag and visually see which users are impacted by the change.
7+
8+

css/style.css

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*{
2+
margin:0;
3+
padding:0;
4+
border:0;
5+
}
6+
table{
7+
height:100%;
8+
position:absolute;
9+
}
10+
.red{
11+
background-color: red;
12+
border: 1px black solid;
13+
}
14+
.green{
15+
background-color: lawngreen;
16+
border: 1px black solid;
17+
}
18+
.grey{
19+
background-color: lightgrey;
20+
border: 1px black solid;
21+
}

docs/demo.mp4

888 KB
Binary file not shown.

flags.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
color-box:
2+
percentage: 100
3+
true: green
4+
false: red
5+
default: grey
6+
disable: false

go-feature-flag-demo

22.7 MB
Binary file not shown.

go.mod

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module go-feature-flag-demo
2+
3+
go 1.17
4+
5+
require github.com/thomaspoignant/go-feature-flag v0.22.2
6+
7+
require (
8+
cloud.google.com/go v0.100.2 // indirect
9+
cloud.google.com/go/compute v1.6.0 // indirect
10+
cloud.google.com/go/iam v0.3.0 // indirect
11+
cloud.google.com/go/storage v1.22.0 // indirect
12+
github.com/antlr/antlr4 v0.0.0-20201206235148-c87e55b61113 // indirect
13+
github.com/aws/aws-sdk-go v1.44.5 // indirect
14+
github.com/blang/semver v3.5.1+incompatible // indirect
15+
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
16+
github.com/golang/protobuf v1.5.2 // indirect
17+
github.com/google/go-cmp v0.5.8 // indirect
18+
github.com/google/uuid v1.3.0 // indirect
19+
github.com/googleapis/gax-go/v2 v2.3.0 // indirect
20+
github.com/googleapis/go-type-adapters v1.0.0 // indirect
21+
github.com/jmespath/go-jmespath v0.4.0 // indirect
22+
github.com/labstack/echo/v4 v4.7.2 // indirect
23+
github.com/labstack/gommon v0.3.1 // indirect
24+
github.com/mattn/go-colorable v0.1.11 // indirect
25+
github.com/mattn/go-isatty v0.0.14 // indirect
26+
github.com/nikunjy/rules v0.0.0-20200120082459-0b7c4dc9dc86 // indirect
27+
github.com/pelletier/go-toml v1.9.5 // indirect
28+
github.com/valyala/bytebufferpool v1.0.0 // indirect
29+
github.com/valyala/fasttemplate v1.2.1 // indirect
30+
go.opencensus.io v0.23.0 // indirect
31+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
32+
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
33+
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
34+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
35+
golang.org/x/text v0.3.7 // indirect
36+
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
37+
google.golang.org/api v0.77.0 // indirect
38+
google.golang.org/appengine v1.6.7 // indirect
39+
google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4 // indirect
40+
google.golang.org/grpc v1.45.0 // indirect
41+
google.golang.org/protobuf v1.28.0 // indirect
42+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
43+
)

go.sum

+699
Large diffs are not rendered by default.

js/script.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setTimeout(function () { location.reload(1); }, 500)

main.go

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"fmt"
7+
"github.com/google/uuid"
8+
"github.com/labstack/echo/v4"
9+
"github.com/thomaspoignant/go-feature-flag"
10+
"github.com/thomaspoignant/go-feature-flag/ffuser"
11+
"html/template"
12+
"io"
13+
"net/http"
14+
"time"
15+
)
16+
17+
var users = make(map[string]ffuser.User, 2500)
18+
19+
func main() {
20+
configFile := flag.String("configFile", "./flags.yaml", "flags.yaml")
21+
flag.Parse()
22+
23+
_ = ffclient.Init(ffclient.Config{
24+
PollingInterval: 1 * time.Second,
25+
Context: context.Background(),
26+
Retriever: &ffclient.FileRetriever{
27+
Path: *configFile,
28+
},
29+
})
30+
31+
// Instantiate a template registry and register all html files inside the view folder
32+
33+
e := echo.New()
34+
e.HideBanner = true
35+
e.Static("/js", "js")
36+
e.Static("/css", "css")
37+
e.Renderer = &TemplateRegistry{templates: template.Must(template.ParseGlob("view/*.html"))}
38+
39+
// init ids
40+
for i := 0; i < 2500; i++ {
41+
id := uuid.New()
42+
u := ffuser.NewUser(id.String())
43+
users[fmt.Sprintf("user%d", i)] = u
44+
}
45+
46+
e.GET("/", apiHandler)
47+
e.Logger.Fatal(e.Start(":8080"))
48+
}
49+
50+
type TemplateRegistry struct {
51+
templates *template.Template
52+
}
53+
54+
func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
55+
return t.templates.ExecuteTemplate(w, name, data)
56+
}
57+
58+
func apiHandler(c echo.Context) error {
59+
mapToRender := make(map[string]string, 2500)
60+
for k, user := range users {
61+
color, _ := ffclient.StringVariation("color-box", user, "grey")
62+
mapToRender[k] = color
63+
}
64+
return c.Render(http.StatusOK, "template.html", mapToRender)
65+
}

0 commit comments

Comments
 (0)