I was thinking of ways to do routing with the standard library. Is it valid to have a handler function that will call other handler functions depending on the request type? e.g.
func main() {
m := http.NewServeMux()
m.HandleFunc("/books", books)
// ...
}
func books(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
getBooks(w, r)
case "POST":
createBook(w, r)
}
}
Is this good practice? I didn't want to declare a custom handler since I find functions to be a bit cleaner.