Admin endpoints

This commit is contained in:
Aurélie Delhaie
2022-06-14 20:34:55 +02:00
parent 3caa99b22a
commit 5ed0cfa837
8 changed files with 304 additions and 19 deletions

View File

@@ -42,6 +42,27 @@ func internalServerError(w http.ResponseWriter, r *http.Request) {
}
}
func notFound(message string, w http.ResponseWriter, r *http.Request) {
e := httpError{
Status: 404,
Error: "Not Found",
Message: message,
Path: r.RequestURI,
Timestamp: time.Now(),
}
payload, err := json.Marshal(e)
if err != nil {
log.Println(err)
}
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(404)
_, err = w.Write(payload)
if err != nil {
log.Println(err)
}
}
func unauthorized(w http.ResponseWriter, r *http.Request) {
e := httpError{
Status: 401,