34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
func (api *API) registerRoutes() {
|
|
api.Router.HandleFunc("/MediaItems", api.mediaItemsHandler)
|
|
api.Router.HandleFunc("/Upload", api.uploadHandler)
|
|
api.Router.HandleFunc("/Albums", api.albumsHandler)
|
|
api.Router.HandleFunc("/Logout", api.logoutHandler)
|
|
api.Router.HandleFunc("/Login", api.loginHandler)
|
|
api.Router.HandleFunc("/Users", api.usersHandler)
|
|
api.Router.HandleFunc("/Tags", api.tagsHandler)
|
|
api.Router.HandleFunc("/Info", api.infoHandler)
|
|
api.Router.HandleFunc("/Me", api.meHandler)
|
|
}
|
|
|
|
// https://stackoverflow.com/a/59764037
|
|
func errorJSON(w http.ResponseWriter, err string, code int) {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
|
w.WriteHeader(code)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{"error": err})
|
|
}
|
|
|
|
func successJSON(w http.ResponseWriter, msg string, code int) {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
|
w.WriteHeader(code)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{"success": msg})
|
|
}
|