在主函数中,我有一个 gorilla mux 路由器,以及一个处理路由的函数。
var router = mux.NewRouter()
func main() {
router.HandleFunc("/", ParseSlash)
http.Handle("/", router)
http.ListenAndServe(":8000", nil)
}
ParseSlash 看起来像
const slash = `<h1>Login</h1>
<form method="post" action="/login">
<label for="name">User name</label>
<input type="text" id="name" name="name">
<label for="password">Password</label>
<input type="password" id="password" name="password">
<button type="submit">Login</button>
</form>`
func ParseSlash(response http.ResponseWriter, request *http.Request) {
fmt.Fprintf(response, slash)
}
但是,在 main 中,我们不是调用函数 as ParseSlash(),而是调用ParseSlashinside router.HandleFunc()。如果我们没有明确提供,函数从哪里获取参数?这种调用函数的方式是什么?
谢谢你。
四季花海
手掌心
相关分类