diff options
Diffstat (limited to 'http')
-rw-r--r-- | http/router.go | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/http/router.go b/http/router.go index a34ff7c..be2a128 100644 --- a/http/router.go +++ b/http/router.go @@ -1,19 +1,22 @@ package http import ( + "bytes" "io" "net/http" "git.capotej.com/capotej/communique/registry" "github.com/gin-gonic/gin" + "go.uber.org/zap" ) type Router struct { registry *registry.Registry + log *zap.SugaredLogger } -func NewRouter(registry *registry.Registry) *Router { - return &Router{registry: registry} +func NewRouter(registry *registry.Registry, log *zap.SugaredLogger) *Router { + return &Router{registry: registry, log: log} } func render(c *gin.Context, resource map[string]interface{}, err error) { @@ -68,17 +71,27 @@ func (s *Router) Start(zapWriter io.Writer) { render(c, resource, err) }) - // // Inbox - // router.POST("/actors/:actor/inbox", func(c *gin.Context) { - // actorParam := c.Param("actor") - // resource := s.registry.Inbox(actorParam) - // if resource != nil { - // c.JSON(http.StatusOK, resource) - // } else { - // c.JSON(http.StatusNotFound, nil) - // } - - // }) + // Inbox + router.POST("/actors/:actor/inbox", func(c *gin.Context) { + log := s.log.With("type", "inbox") + buf := new(bytes.Buffer) + buf.ReadFrom(c.Request.Body) + payload := buf.String() + log.With( + "payload", + c.GetHeader("Signature"), + ).With( + "content-type", + c.GetHeader("Content-Type"), + ).With( + "payload", + payload, + ).Debug("received item") + actorParam := c.Param("actor") + err := s.registry.Inbox(actorParam, c.Request) + resource := map[string]interface{}{} + render(c, resource, err) + }) // Actor Outbox router.GET("/actors/:actor/outbox", func(c *gin.Context) { |