2017-12-28 01:38:30 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
func router() *mux.Router {
|
|
|
|
r := mux.NewRouter()
|
2018-11-04 10:50:03 +00:00
|
|
|
registerAPIv2(r.PathPrefix("/v2").Subrouter())
|
2020-01-11 20:05:11 +00:00
|
|
|
r.PathPrefix("/").HandlerFunc(gzipFunc(serveAssets))
|
2017-12-28 01:38:30 +00:00
|
|
|
return r
|
|
|
|
}
|
2018-11-04 10:50:03 +00:00
|
|
|
|
|
|
|
func registerAPIv2(r *mux.Router) {
|
|
|
|
r.HandleFunc("/login", apiHelper(apiLogin)).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/register", apiHelper(apiRegister)).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/users", apiHelper(apiListUsers)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
r.HandleFunc("/user/{user}/data", apiHelper(apiGetUserData)).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/user/{user}/data", apiHelper(apiSetUserData)).Methods(http.MethodPut)
|
|
|
|
r.HandleFunc("/user/{user}/logout", apiHelper(apiLogoutUser)).Methods(http.MethodPost)
|
|
|
|
r.HandleFunc("/user/{user}/settings", apiHelper(apiGetUserSettings)).Methods(http.MethodGet)
|
|
|
|
r.HandleFunc("/user/{user}/settings", apiHelper(apiSetUserSettings)).Methods(http.MethodPatch)
|
|
|
|
r.HandleFunc("/user/{user}/password", apiHelper(apiChangeLoginPassword)).Methods(http.MethodPut)
|
|
|
|
r.HandleFunc("/user/{user}/validate-mfa", apiHelper(apiValidateMFA)).Methods(http.MethodPost)
|
|
|
|
}
|