From 54b85678185008a4f6b5778460228788e2dd970d Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Tue, 3 Jan 2023 20:29:50 -0500 Subject: start of keypair model and persisting keypairs --- http/router.go | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'http/router.go') 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) { -- cgit v1.2.3