Skip to content

Commit

Permalink
pointer receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
devanbenz committed Jan 24, 2024
1 parent 81feda2 commit 74d44fc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions internal/http/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"] {
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/http/apub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
6 changes: 3 additions & 3 deletions internal/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ 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")
content, _ := json.Marshal(RequestError{Msg: "not found"})
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")
Expand Down
4 changes: 2 additions & 2 deletions internal/http/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions internal/http/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 74d44fc

Please sign in to comment.