-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from sublinks/update-http
- Loading branch information
Showing
12 changed files
with
174 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ | |
|
||
# Go workspace file | ||
go.work | ||
|
||
# jetbrains editor | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package http | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
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) { | ||
w.WriteHeader(http.StatusOK) | ||
w.Header().Add("content-type", "application/activity+json") | ||
} | ||
|
||
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) { | ||
w.WriteHeader(http.StatusOK) | ||
w.Header().Add("content-type", "application/activity+json") | ||
} | ||
|
||
func (server *Server) postOutboxHandler(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
w.Header().Add("content-type", "application/activity+json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package http | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
type RequestError struct { | ||
Msg string `json:"message"` | ||
} | ||
|
||
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) { | ||
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) { | ||
server.Logger.Request("405 Method Not Allowed", r) | ||
w.WriteHeader(http.StatusNotFound) | ||
w.Header().Add("content-type", "application/activity+json") | ||
content, _ := json.Marshal(RequestError{Msg: "method not allowed"}) | ||
w.Write(content) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.