package main
import (
"log"
"net/http"
)
// IndexHandler 首页路由处理函数
func IndexHandler(w http.ResponseWriter, req *http.Request) {
// 响应 hello world
_, err := w.Write([]byte("hello world"))
if err != nil {
log.Fatalln("listen err:", err)
}
}
func main() {
// 注册首页路由的处理函数
http.HandleFunc("/", IndexHandler)
// 监听端口启动服务
err := http.ListenAndServe(":8089", nil)
if err != nil {
log.Fatalln("listen err:", err)
}
}
w http.ResponseWriter, req *http.Request
不知道这是啥意思
有望超过老虎
黑屋屋👾
其次 *http.Request 这个 * 代表啥意思的?
而 req *http.Request 中 req 同样是参数名,*http.Request 则是 http.Request 的指针类型