1. 首页
  2. 主题
  3. Go Web开发

报错:non-declaration statement outside function body

milo · · 13185 次点击
package handle import ( "html/template" "net/http" "utils" ) var regMap = make(map[string]func(http.ResponseWriter, *http.Request)) regMap["/view"] = func (w http.ResponseWriter, r *http.Request) { renderTemplate(w, "edit.html", "a") } // ***这行报:non-declaration statement outside function body*** func Register() { for url, method := range regMap { http.HandleFunc(url, method) } } 为什么? 等待〜
David
Life is hard but please enjoy it!
不过看你的程序,其实没意义,Register 里面一行行写就好了,这个map干啥用的?
#4
更多评论
gofmt运行此代码,报:`expected declaration, found 'IDENT' regMap`
#1
polaris
社区,需要你我一同完善!
把 regMap["/view"] = func(w http.ResponseWriter, r *http.Request) { renderTemplate(w, "edit.html", "a") } 放在函数里面。
#2

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中