报错:non-declaration statement outside function body

milo · · 12541 次点击
David
Life is hard but please enjoy it!
定义一个 init 函数: func init() { regMap["/view"] = func (w http.ResponseWriter, r *http.Request) { renderTemplate(w, "edit.html", "a") } } 或者,写成这样: var regMap = map[string]func(http.ResponseWriter, *http.Request)) { "/view": func (w http.ResponseWriter, r *http.Request) { renderTemplate(w, "edit.html", "a") }, }
#3
更多评论
gofmt运行此代码,报:`expected declaration, found 'IDENT' regMap`
#1
polaris
社区,需要你我一同完善!
把 regMap["/view"] = func(w http.ResponseWriter, r *http.Request) { renderTemplate(w, "edit.html", "a") } 放在函数里面。
#2