February 2018
Intermediate to advanced
340 pages
9h 43m
English
package main import ( "fmt" "net/http" ) func main() { mux := http.NewServeMux() mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodGet { fmt.Fprintln(w, "User GET") } if r.Method == http.MethodPost { fmt.Fprintln(w, "User POST") } }) // separate handler itemMux := http.NewServeMux() itemMux.HandleFunc("/items/clothes", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Clothes") }) mux.Handle("/items/", itemMux) // Admin handlers adminMux := http.NewServeMux() adminMux.HandleFunc("/ports", func(w http.ResponseWriter, r *http.Request) ...Read now
Unlock full access