diff options
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | cgi/servers.go | 2 | ||||
-rw-r--r-- | http/server.go | 28 | ||||
-rw-r--r-- | main.go | 44 |
4 files changed, 44 insertions, 32 deletions
@@ -1,3 +1,3 @@ # Communique -Communique is an activity pub platform that abstracts outboxes/inboxes away from handler implementations.
\ No newline at end of file +Communique aims to be an activitypub platform that abstracts outboxes/inboxes away from handler implementations.
\ No newline at end of file diff --git a/cgi/servers.go b/cgi/servers.go index b18c6a3..0f23aac 100644 --- a/cgi/servers.go +++ b/cgi/servers.go @@ -21,7 +21,7 @@ func NewServers() *Servers { } // Start iterates over all Handlers and starts an internal CGI server for each one -// along with ticker for the configured handler interval and blocks forever +// along with ticker for the configured handler interval then blocks indefinitely func (s *Servers) Start(cfg config.Config) { var wg sync.WaitGroup diff --git a/http/server.go b/http/server.go new file mode 100644 index 0000000..25c51d8 --- /dev/null +++ b/http/server.go @@ -0,0 +1,28 @@ +package http + +import ( + "io" + "net/http" + + "github.com/gin-gonic/gin" +) + +type Server struct{} + +func NewServer() *Server { + return &Server{} +} + +func (s *Server) Start(zapWriter io.Writer) { + router := gin.Default() + router.SetTrustedProxies(nil) + gin.DisableConsoleColor() + gin.DefaultWriter = zapWriter // send gin logs to zap + + router.GET("/.well-known/webfinger", func(c *gin.Context) { + // resource := c.Query("resource") + c.JSON(http.StatusOK, nil) + }) + + router.Run() +} @@ -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() } |