From 2585e05af116cb95d2d2c36b096345c2b982e39c Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Sat, 17 Dec 2022 15:22:52 -0500 Subject: refactor --- main.go | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 195e02d..5935bc9 100644 --- a/main.go +++ b/main.go @@ -1,15 +1,14 @@ package main import ( - "net/http" + "sync" "git.capotej.com/capotej/communique/cgi" "git.capotej.com/capotej/communique/config" + "git.capotej.com/capotej/communique/http" "github.com/BurntSushi/toml" "go.uber.org/zap" "go.uber.org/zap/zapio" - - "github.com/gin-gonic/gin" ) func main() { @@ -26,36 +25,21 @@ func main() { if err != nil { log.Fatal(err) } - log.Debugf("Loaded TOML Config: %+v", cfg) - // Server + var mainWg sync.WaitGroup + + // Internal CGI Servers + cgiServers := cgi.NewServers() + mainWg.Add(1) + go cgiServers.Start(cfg) + + // External Http Server writer := &zapio.Writer{Log: logger, Level: zap.DebugLevel} defer writer.Close() + server := http.NewServer() + mainWg.Add(1) + go server.Start(writer) - // 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() + mainWg.Wait() } -- cgit v1.2.3