aboutsummaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2023-01-04 01:29:50 +0000
committerJulio Capote <jcapote@gmail.com>2023-01-04 01:29:50 +0000
commit54b85678185008a4f6b5778460228788e2dd970d (patch)
treebcce8ac619da7c438518801df4a57be2401f7596 /http
parenta40781358984f651214e53ba000ccc288c56d4f1 (diff)
downloadcommunique-54b85678185008a4f6b5778460228788e2dd970d.tar.gz
start of keypair model and persisting keypairs
Diffstat (limited to '')
-rw-r--r--http/router.go39
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) {