github.com/nibnait/go-learn@v0.0.0-20220227013611-dfa47ea6d2da/src/main/chapter/ch8_02_http/hello_http.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "net/http" 6 "time" 7 ) 8 9 func main() { 10 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 11 fmt.Fprintf(w, "Hello World!") 12 }) 13 http.HandleFunc("/time/", func(w http.ResponseWriter, r *http.Request) { 14 t := time.Now() 15 timeStr := fmt.Sprintf("{\"time\": \"%s\"}", t) 16 w.Write([]byte(timeStr)) 17 }) 18 19 http.ListenAndServe(":8080", nil) 20 }