From 7baee5b892afcddb72a575282c6c8983d477ed44 Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Sat, 17 Dec 2022 16:19:49 -0500 Subject: introduce concept of registry, start of webfinger impl --- http/server.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'http/server.go') diff --git a/http/server.go b/http/server.go index 25c51d8..6d68d0e 100644 --- a/http/server.go +++ b/http/server.go @@ -4,13 +4,16 @@ import ( "io" "net/http" + "git.capotej.com/capotej/communique/registry" "github.com/gin-gonic/gin" ) -type Server struct{} +type Server struct { + registry *registry.Registry +} -func NewServer() *Server { - return &Server{} +func NewServer(registry *registry.Registry) *Server { + return &Server{registry: registry} } func (s *Server) Start(zapWriter io.Writer) { @@ -20,8 +23,14 @@ func (s *Server) Start(zapWriter io.Writer) { 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) + resourceParam := c.Query("resource") + resource := s.registry.LookupResource(resourceParam) + if resource != nil { + c.JSON(http.StatusOK, resource) + } else { + c.JSON(http.StatusNotFound, nil) + } + }) router.Run() -- cgit v1.2.3