aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2023-01-01 21:53:09 +0000
committerJulio Capote <jcapote@gmail.com>2023-01-01 21:53:09 +0000
commitaf4dc7f3f05fad8fe13edf0173a6dee5e4148bd3 (patch)
tree100caca9cb134ab00f73c60c0ed5bb4adabd12fc
parent2969956f7eac5fb18fe3bcad24bdc08ee63497af (diff)
downloadcommunique-af4dc7f3f05fad8fe13edf0173a6dee5e4148bd3.tar.gz
rename server to router
Diffstat (limited to '')
-rw-r--r--http/router.go (renamed from http/server.go)26
-rw-r--r--main.go4
2 files changed, 22 insertions, 8 deletions
diff --git a/http/server.go b/http/router.go
index 7d18085..204243f 100644
--- a/http/server.go
+++ b/http/router.go
@@ -8,16 +8,15 @@ import (
"github.com/gin-gonic/gin"
)
-// TODO rename to Router and router.go
-type Server struct {
+type Router struct {
registry *registry.Registry
}
-func NewServer(registry *registry.Registry) *Server {
- return &Server{registry: registry}
+func NewRouter(registry *registry.Registry) *Router {
+ return &Router{registry: registry}
}
-func (s *Server) Start(zapWriter io.Writer) {
+func (s *Router) Start(zapWriter io.Writer) {
router := gin.Default()
router.SetTrustedProxies(nil)
gin.DisableConsoleColor()
@@ -78,7 +77,22 @@ func (s *Server) Start(zapWriter io.Writer) {
})
// Single activity
- router.GET("/actors/:actor/outbox/:id/activity", func(c *gin.Context) {
+ router.GET("/actors/:actor/activity/:id", func(c *gin.Context) {
+ actorParam := c.Param("actor")
+ idParam := c.Param("id")
+ var resource map[string]interface{}
+ resource, _ = s.registry.Activity(actorParam, idParam)
+
+ if resource != nil {
+ c.Writer.Header().Set("Content-Type", "application/activity+json")
+ c.JSON(http.StatusOK, resource)
+ } else {
+ c.JSON(http.StatusNotFound, nil)
+ }
+ })
+
+ // Single note
+ router.GET("/actors/:actor/activity/:id/note", func(c *gin.Context) {
actorParam := c.Param("actor")
idParam := c.Param("id")
var resource map[string]interface{}
diff --git a/main.go b/main.go
index fa81264..35b5b80 100644
--- a/main.go
+++ b/main.go
@@ -56,9 +56,9 @@ func main() {
// // External Http Server
writer := &zapio.Writer{Log: logger, Level: zap.DebugLevel}
defer writer.Close()
- server := http.NewServer(registry)
+ router := http.NewRouter(registry)
mainWg.Add(1)
- go server.Start(writer)
+ go router.Start(writer)
mainWg.Wait()
}