September 2017
Intermediate to advanced
466 pages
9h 33m
English
The web server implementation of this section will support multiple paths with the help of http.ServeMux, which will be illustrated in the serveMux.go program that will be displayed in four parts.
The first part of the program is the following:
package main import ( "fmt" "net/http" "time" )
The second part of serveMux.go has the following Go code:
func about(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "This is the /about page at %s\n", r.URL.Path) fmt.Printf("Served: %s\n", r.Host) } func cv(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "This is the /CV page at %s\n", r.URL.Path) fmt.Printf("Served: %s\n", r.Host) } func timeHandler(w http.ResponseWriter, r *http.Request) { currentTime := time.Now().Format(time.RFC1123) ...Read now
Unlock full access