aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--cgi/servers.go2
-rw-r--r--http/server.go28
-rw-r--r--main.go44
4 files changed, 44 insertions, 32 deletions
diff --git a/README b/README
index 263210c..f968c2d 100644
--- a/README
+++ b/README
@@ -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()
+}
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()
}