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