func main() { http.HandleFunc("/", foo) http.ListenAndServe(":3000", nil)}func foo(w http.ResponseWriter, r *http.Request) { s:= "name" fp := path.Join("templates", "index.html") tmpl, err := template.ParseFiles(fp) if err != nil { panic(err) } if err := tmpl.Execute(w, s); err != nil { panic(err) } fmt.Println("successfull Operation!!")}此代碼顯示 2 "successfull Operation!!" 但是當(dāng)我添加/home( http.HandleFunc("/home", foo)) 時(shí),它沒(méi)有。我想知道為什么顯示“成功操作??!” 兩次。先感謝您。
1 回答

牛魔王的故事
TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊
因?yàn)楝F(xiàn)代瀏覽器會(huì)發(fā)送一個(gè)額外的請(qǐng)求,/favicon.ico
該請(qǐng)求也在您的/
請(qǐng)求處理程序中處理。
curl
例如,如果您 ping 您的服務(wù)器,您將看到只有一個(gè)請(qǐng)求被發(fā)送:
curl localhost:3000
- 1 回答
- 0 關(guān)注
- 181 瀏覽
添加回答
舉報(bào)
0/150
提交
取消