go-http

A

➜  hour18 cat example01.go 
package main

import (
	"net/http"
)

func helloWorld(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("Hello World\n"))
}

func main() {
	http.HandleFunc("/", helloWorld)
	http.ListenAndServe(":8000", nil)
}
➜  hour18 go run  example01.go

➜  ~ curl -is http://localhost:8000
HTTP/1.1 200 OK
Date: Mon, 24 May 2021 11:41:07 GMT
Content-Length: 12
Content-Type: text/plain; charset=utf-8

Hello World

B

路由器默认将没有指定处理程序的请求定向到 /
路由必须完全匹配。例如,对于向 /users发出的请求,将定向到 /,因为这里末尾少了斜杆

这里要说的是,发送响应应是最后一步