本文共 368 字,大约阅读时间需要 1 分钟。
package mainimport ( //"fmt" "net/http" "log" "io")type WebServerHandler struct {}func (ws WebServerHandler) ServeHTTP(w http.ResponseWriter, req *http.Request){ //fmt.Fprintln(w, "hello the world!") io.WriteString(w, "hello, world!\n")}func main() { var handler WebServerHandler err := http.ListenAndServe("localhost:8000", handler) if err != nil { log.Fatal(err) }}