44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"arimelody.me/arimelody.me/admin"
|
|
music "arimelody.me/arimelody.me/music/view"
|
|
)
|
|
|
|
func Handler() http.Handler {
|
|
mux := http.NewServeMux()
|
|
|
|
mux.Handle("/v1/artist/", http.StripPrefix("/v1/artist", ServeArtist()))
|
|
mux.Handle("/v1/artist", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.Method {
|
|
case http.MethodGet:
|
|
ServeAllArtists().ServeHTTP(w, r)
|
|
return
|
|
case http.MethodPost:
|
|
admin.MustAuthorise(CreateArtist()).ServeHTTP(w, r)
|
|
return
|
|
default:
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
}))
|
|
mux.Handle("/v1/music/", http.StripPrefix("/v1/music", music.ServeRelease()))
|
|
mux.Handle("/v1/music", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.Method {
|
|
case http.MethodGet:
|
|
ServeCatalog().ServeHTTP(w, r)
|
|
return
|
|
case http.MethodPost:
|
|
admin.MustAuthorise(CreateRelease()).ServeHTTP(w, r)
|
|
return
|
|
default:
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
}))
|
|
|
|
return mux
|
|
}
|