functimeHandler(w http.ResponseWriter, r *http.Request) { t := time.Now().Format(time.RFC1123) Body :="The current time is:" fmt.Fprintf(w, "<h1 align=\"center\">%s</h1>", Body) fmt.Fprintf(w, "<h2 align=\"center\">%s</h2>n", t) fmt.Fprintf(w, "Serving: %s\n", r.URL.Path) fmt.Printf("Served time for :%s\n", r.Host)}
serverTimeOut.go 的第三段代码如下:
funcmain() { PORT :=":8001" arguments := os.Argsiflen(arguments) ==1 { fmt.Printf("Listening on http://0.0.0.0%s\n", PORT) } else { PORT =":"+ arguments[1] fmt.Printf("Listening on http://0.0.0.0%s\n", PORT) } m := http.NewServeMux() srv :=&http.Server { Addr: PORT, Handler: m, ReadTimeout: 3* time.Second, WriteTimeout: 3* time.Second, }