This recipe gives advice on how the HTTP handlers could be separated into modules.
Breaking HTTP handlers into groups
How to do it...
- Open the console and create the folder chapter11/recipe08.
- Navigate to the directory.
- Create the file handlegroups.go with the following content:
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
log.Println("Staring server...")
// Adding to mani Mux
mainMux := http.NewServeMux()
mainMux.Handle("/api/",
http.StripPrefix("/api", restModule()))
mainMux.Handle("/ui/",
http.StripPrefix("...