This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/internal/api/routes.go

67 lines
2.0 KiB
Go
Raw Normal View History

2021-01-16 22:00:17 +00:00
package api
import (
"encoding/json"
"net/http"
)
func (api *API) registerRoutes() {
2021-01-22 05:00:55 +00:00
api.Router.HandleFunc("/media/", multipleMiddleware(
api.mediaHandler,
api.authMiddleware,
))
2021-01-19 20:50:48 +00:00
api.Router.HandleFunc("/api/v1/MediaItems", multipleMiddleware(
2021-01-18 04:56:56 +00:00
api.mediaItemsHandler,
api.authMiddleware,
))
2021-01-19 20:50:48 +00:00
api.Router.HandleFunc("/api/v1/Devices", multipleMiddleware(
api.devicesHandler,
api.authMiddleware,
))
api.Router.HandleFunc("/api/v1/Upload", multipleMiddleware(
2021-01-18 04:56:56 +00:00
api.uploadHandler,
api.authMiddleware,
))
2021-01-19 20:50:48 +00:00
api.Router.HandleFunc("/api/v1/Albums", multipleMiddleware(
2021-01-18 04:56:56 +00:00
api.albumsHandler,
api.authMiddleware,
))
2021-01-19 20:50:48 +00:00
api.Router.HandleFunc("/api/v1/Users", multipleMiddleware(
2021-01-18 04:56:56 +00:00
api.usersHandler,
api.authMiddleware,
))
2021-01-19 20:50:48 +00:00
api.Router.HandleFunc("/api/v1/Tags", multipleMiddleware(
2021-01-18 04:56:56 +00:00
api.tagsHandler,
api.authMiddleware,
))
2021-01-19 20:50:48 +00:00
api.Router.HandleFunc("/api/v1/Info", multipleMiddleware(
2021-01-18 04:56:56 +00:00
api.infoHandler,
api.authMiddleware,
))
2021-01-19 20:50:48 +00:00
api.Router.HandleFunc("/api/v1/Me", multipleMiddleware(
2021-01-18 04:56:56 +00:00
api.meHandler,
api.authMiddleware,
))
2021-01-19 20:50:48 +00:00
api.Router.HandleFunc("/api/v1/Logout", api.logoutHandler)
api.Router.HandleFunc("/api/v1/Login", api.loginHandler)
api.Router.HandleFunc("/api/v1/RefreshLogin", api.refreshLoginHandler)
2021-01-16 22:00:17 +00:00
}
2021-01-19 20:50:48 +00:00
2021-01-16 22:00:17 +00:00
// 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})
}