// http.go
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
fmt.Println("Hello World!")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, this is http server! " + r.URL.String()))
})
http.HandleFunc("/bye", sayBye)
log.Println("Starting server ...")
log.Fatal((http.ListenAndServe(":8888", nil)))
}
func sayBye(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Bye bye, this is http server! " + r.URL.String()))
}
有疑问加站长微信联系(非本文作者)