aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2022-12-17 15:31:03 +0000
committerJulio Capote <jcapote@gmail.com>2022-12-17 15:31:03 +0000
commitd3fb280a146759ca1468c1773f41599b4fabb5fa (patch)
tree931e475e12baf1aecd76d8fab80c10b4b3d3c83d /main.go
downloadcommunique-d3fb280a146759ca1468c1773f41599b4fabb5fa.tar.gz
initial
Diffstat (limited to '')
-rw-r--r--main.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..dcf6034
--- /dev/null
+++ b/main.go
@@ -0,0 +1,59 @@
+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()
+ 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)
+ })
+
+ router.Run()
+}