[beego]8088后台出错

2024-01-30 356 views
4

发生错误的访问命令listconf?command=router,其他命令正常 ----错误信息----- 2014/06/10 16:53:00 http: panic serving 127.0.0.1:62248: runtime error: invalid memory address or nil pointer dereferenc e goroutine 24 [running]: net/http.func·009() C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1093 +0xb1 runtime.panic(0x783bc0, 0xc4a0af) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/runtime/panic.c:248 +0x11b github.com/astaxie/beego.listConf(0x3176d8, 0xc084119500, 0xc084118c30) D:/GOLANG/TPPkg/src/github.com/astaxie/beego/admin.go:129 +0x5301 net/http.HandlerFunc.ServeHTTP(0x8cb810, 0x3176d8, 0xc084119500, 0xc084118c30) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1220 +0x43 net/http.(_ServeMux).ServeHTTP(0xc08403eb10, 0x3176d8, 0xc084119500, 0xc084118c30) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1496 +0x166 net/http.serverHandler.ServeHTTP(0xc0841050a0, 0x3176d8, 0xc084119500, 0xc084118c30) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1597 +0x171 net/http.(_conn).serve(0xc084061000) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1167 +0x7ba created by net/http.(_Server).Serve C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1644 +0x28e 2014/06/10 16:53:00 http: panic serving 127.0.0.1:62251: runtime error: invalid memory address or nil pointer dereferenc e goroutine 25 [running]: net/http.func·009() C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1093 +0xb1 runtime.panic(0x783bc0, 0xc4a0af) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/runtime/panic.c:248 +0x11b github.com/astaxie/beego.listConf(0x3176d8, 0xc0841425a0, 0xc08409b680) D:/GOLANG/TPPkg/src/github.com/astaxie/beego/admin.go:129 +0x5301 net/http.HandlerFunc.ServeHTTP(0x8cb810, 0x3176d8, 0xc0841425a0, 0xc08409b680) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1220 +0x43 net/http.(_ServeMux).ServeHTTP(0xc08403eb10, 0x3176d8, 0xc0841425a0, 0xc08409b680) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1496 +0x166 net/http.serverHandler.ServeHTTP(0xc0841050a0, 0x3176d8, 0xc0841425a0, 0xc08409b680) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1597 +0x171 net/http.(_conn).serve(0xc08410fb80) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1167 +0x7ba created by net/http.(_Server).Serve C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist667667715/go/src/pkg/net/http/server.go:1644 +0x28e

回答

5

你注册了函数?

6

没明白谢大说的注册函数是指? 我route里面的代码: package routers

import ( "beegoExer/controllers" "github.com/astaxie/beego" )

func init() { adminNS := beego.NewNamespace("/admin"). Router("/index", &controllers.MainController{}, ":Get"). Namespace(beego.NewNamespace("/index"). Router("/:params", &controllers.MainController{}, ":Get"))

beego.AddNamespace(adminNS)

}

4

这个Router好像写的不对啊

6

想实现的功能是 /admin/index 和 /admin/index/xxx/xxx/xxx(后面的xxx可以任意长度的)都route给同一controller的同一个函数处理。前面的admin段,可以在配置文件里修改。 这个route的写法困惑了很久,如果用AutoRoute,由于admin是可变的,/:controller/:method 实际是对应不上的 上面的代码没注意,*被md了

7

package routers

import ( "beegoExer/controllers" "github.com/astaxie/beego" )

func init() { adminNS := beego.NewNamespace("/admin"). Router("/index", &controllers.MainController{}, ":Get"). Namespace(beego.NewNamespace("/index"). Router("/:params", &controllers.MainController{}, ":Get"))

beego.AddNamespace(adminNS) }