blob: 195e02de592ebfa7fef969141d0b8b3e07b0759d (
plain)
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
|
package main
import (
"net/http"
"git.capotej.com/capotej/communique/cgi"
"git.capotej.com/capotej/communique/config"
"github.com/BurntSushi/toml"
"go.uber.org/zap"
"go.uber.org/zap/zapio"
"github.com/gin-gonic/gin"
)
func main() {
// ctx := context.Background()
// Logger
logger, _ := zap.NewDevelopment()
defer logger.Sync() // flushes buffer, if any
log := logger.Sugar()
// Config
var cfg config.Config
//TODO use a flag here
_, err := toml.DecodeFile("sample-config.toml", &cfg)
if err != nil {
log.Fatal(err)
}
log.Debugf("Loaded TOML Config: %+v", cfg)
// Server
writer := &zapio.Writer{Log: logger, Level: zap.DebugLevel}
defer writer.Close()
// CGI Servers
servers := cgi.NewServers()
// TODO Should probably be in a global waitgroup
go servers.Start(cfg)
// HTTP Server
router := gin.Default()
router.SetTrustedProxies(nil)
gin.DisableConsoleColor()
gin.DefaultWriter = writer // send gin logs to zap
router.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
// This handler will match /user/john but will not match /user/ or /user
router.GET("/.well-known/webfinger", func(c *gin.Context) {
// resource := c.Query("resource")
c.JSON(http.StatusOK, nil)
})
// TODO Should probably be in a global waitgroup
router.Run()
}
|