refactor mux path routes
legend has it that if you refactor your code enough times, one day you will finally be happy
This commit is contained in:
parent
82fd17c836
commit
21912d4ec2
17 changed files with 102 additions and 469 deletions
|
|
@ -9,9 +9,17 @@ func Handler(app *model.AppState) http.Handler {
|
|||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/releases/", serveReleases(app))
|
||||
mux.Handle("/artists/", serveArtists(app))
|
||||
mux.Handle("/tracks/", serveTracks(app))
|
||||
mux.Handle("/releases/", http.StripPrefix("/releases", serveReleases(app)))
|
||||
|
||||
mux.HandleFunc("/artists/{id}", func(w http.ResponseWriter, r *http.Request) {
|
||||
serveArtist(app, r.PathValue("id")).ServeHTTP(w, r)
|
||||
})
|
||||
mux.Handle("/artists/", http.StripPrefix("/artists", serveArtists(app)))
|
||||
|
||||
mux.HandleFunc("/tracks/{id}", func(w http.ResponseWriter, r *http.Request) {
|
||||
serveTrack(app, r.PathValue("id")).ServeHTTP(w, r)
|
||||
})
|
||||
mux.Handle("/tracks/", http.StripPrefix("/tracks", serveTracks(app)))
|
||||
|
||||
mux.ServeHTTP(w, r)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue