-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (49 loc) · 1.31 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
// SPDX-License-Identifier: MPL-2.0
package main
import (
"context"
"log"
healthcheck "github.com/RaMin0/gin-health-check"
"github.com/gin-contrib/logger"
"github.com/gin-contrib/requestid"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"github.com/sethvargo/go-envconfig"
)
func main() {
if err := envconfig.Process(context.Background(), &cfg); err != nil {
log.Fatal(err)
}
if cfg.Dev {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
}
r := gin.New()
_ = r.SetTrustedProxies(nil)
r.Use(gin.Recovery())
r.Use(healthcheck.Default())
r.Use(requestid.New())
r.Use(logger.SetLogger(
logger.WithLogger(func(_ *gin.Context, l zerolog.Logger) zerolog.Logger {
return l.Output(gin.DefaultWriter).With().Logger()
}),
))
r.Use(UnitedSetup())
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
state := r.Group("/state", UnitedBasicAuth())
{
state.GET("/:group/:name", getHandler)
state.POST("/:group/:name", postHandler)
// Tested in the http backend tf code, but I'm iffy if this is ever actually called
state.DELETE("/:group/:name", deleteHandler)
// LOCK and UNLOCK, don't have helper handlers in gin
state.Handle("LOCK", "/:group/:name", lockHandler)
state.Handle("UNLOCK", "/:group/:name", unlockHandler)
}
_ = r.Run()
}