diff --git a/internal/http/activity.go b/internal/http/activity.go index c047bdf..15e2697 100644 --- a/internal/http/activity.go +++ b/internal/http/activity.go @@ -14,11 +14,11 @@ import ( "github.com/gorilla/mux" ) -func (server Server) SetupActivityRoutes() { +func (server *Server) SetupActivityRoutes() { server.Router.HandleFunc("/activities/{action}/{id}", server.getActivityHandler).Methods("GET") } -func (server Server) getActivityHandler(w http.ResponseWriter, r *http.Request) { +func (server *Server) getActivityHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) var content []byte switch vars["action"] { @@ -52,7 +52,7 @@ func (server Server) getActivityHandler(w http.ResponseWriter, r *http.Request) w.Write(content) } -func (server Server) GetPostActivityObject(id string) (*activitypub.Post, error) { +func (server *Server) GetPostActivityObject(id string) (*activitypub.Post, error) { ctx := context.Background() c := lemmy.GetLemmyClient(ctx) post, err := c.GetPost(ctx, id) diff --git a/internal/http/apub.go b/internal/http/apub.go index 83ab759..0f34218 100644 --- a/internal/http/apub.go +++ b/internal/http/apub.go @@ -4,29 +4,29 @@ import ( "net/http" ) -func (server Server) SetupApubRoutes() { +func (server *Server) SetupApubRoutes() { server.Router.HandleFunc("/users/{user}/inbox", server.getInboxHandler).Methods("GET") server.Router.HandleFunc("/users/{user}/inbox", server.postInboxHandler).Methods("POST") server.Router.HandleFunc("/users/{user}/outbox", server.getOutboxHandler).Methods("GET") server.Router.HandleFunc("/users/{user}/outbox", server.postOutboxHandler).Methods("POST") } -func (server Server) getInboxHandler(w http.ResponseWriter, r *http.Request) { +func (server *Server) getInboxHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Add("content-type", "application/activity+json") } -func (server Server) postInboxHandler(w http.ResponseWriter, r *http.Request) { +func (server *Server) postInboxHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Add("content-type", "application/activity+json") } -func (server Server) getOutboxHandler(w http.ResponseWriter, r *http.Request) { +func (server *Server) getOutboxHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Add("content-type", "application/activity+json") } -func (server Server) postOutboxHandler(w http.ResponseWriter, r *http.Request) { +func (server *Server) postOutboxHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Add("content-type", "application/activity+json") } diff --git a/internal/http/middleware.go b/internal/http/middleware.go index 27aa1a7..9bb8e53 100644 --- a/internal/http/middleware.go +++ b/internal/http/middleware.go @@ -9,14 +9,14 @@ type RequestError struct { Msg string `json:"message"` } -func (server Server) logMiddleware(next http.Handler) http.Handler { +func (server *Server) logMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { server.Logger.Request("", r) next.ServeHTTP(w, r) }) } -func (server Server) notFound(w http.ResponseWriter, r *http.Request) { +func (server *Server) notFound(w http.ResponseWriter, r *http.Request) { server.Logger.Request("404 Not Found", r) w.WriteHeader(http.StatusNotFound) w.Header().Add("content-type", "application/activity+json") @@ -24,7 +24,7 @@ func (server Server) notFound(w http.ResponseWriter, r *http.Request) { w.Write(content) } -func (server Server) notAllowedMethod(w http.ResponseWriter, r *http.Request) { +func (server *Server) notAllowedMethod(w http.ResponseWriter, r *http.Request) { server.Logger.Request("405 Method Not Allowed", r) w.WriteHeader(http.StatusNotFound) w.Header().Add("content-type", "application/activity+json") diff --git a/internal/http/post.go b/internal/http/post.go index bb6486f..859b871 100644 --- a/internal/http/post.go +++ b/internal/http/post.go @@ -9,11 +9,11 @@ import ( "sublinks/sublinks-federation/internal/lemmy" ) -func (server Server) SetupPostRoutes() { +func (server *Server) SetupPostRoutes() { server.Router.HandleFunc("/post/{postId}", server.getPostHandler).Methods("GET") } -func (server Server) getPostHandler(w http.ResponseWriter, r *http.Request) { +func (server *Server) getPostHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) ctx := context.Background() c := lemmy.GetLemmyClient(ctx) diff --git a/internal/http/server.go b/internal/http/server.go index 1410fb8..086239d 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -25,7 +25,7 @@ func NewServer(logger log.Logger) *Server { } } -func (server Server) RunServer() { +func (server *Server) RunServer() { var wait time.Duration flag.DurationVar(&wait, "graceful-timeout", time.Second*15, "the duration for which the server gracefully wait for existing connections to finish - e.g. 15s or 1m") flag.Parse() diff --git a/internal/http/user.go b/internal/http/user.go index 4b87a35..85e2f82 100644 --- a/internal/http/user.go +++ b/internal/http/user.go @@ -10,11 +10,11 @@ import ( "sublinks/sublinks-federation/internal/lemmy" ) -func (server Server) SetupUserRoutes() { +func (server *Server) SetupUserRoutes() { server.Router.HandleFunc("/u/{user}", server.getUserInfoHandler).Methods("GET") } -func (server Server) getUserInfoHandler(w http.ResponseWriter, r *http.Request) { +func (server *Server) getUserInfoHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) ctx := context.Background() c := lemmy.GetLemmyClient(ctx)