Beego: 运行bee run时会报routers/commentsRouter_xxx_controllers.go: too few values in struct initializer

Created on 21 May 2017  ·  15Comments  ·  Source: astaxie/beego

出错的地方在routers/commentsRouter_xxx_controllers.go文件的beego.ControllerComments初始化处:
beego.ControllerComments{ "Post", /, []string{"post"}, nil})

查看了beego的源码,ControllerComments定义在beego/controller.go中:
type ControllerComments struct {
Method string
Router string
AllowHTTPMethods []string
Params []map[string]string
MethodParams []*param.MethodParam
}
这个定义中需要5个变量,而我的routers/commentsRouter_xxx_controllers.go中的beego.ControllerComments初始化时却只有4个变量
同时,routers/commentsRouter_xxx_controllers.go这个文件应该是自动生成的,想请问下这个问题怎么解决?

Most helpful comment

in beego 1.8.4 another parameter was added to ControllerComments. You can add nil to last item and then try to regenerate the source. Which version of beego did you upgrade from?

All 15 comments

my bee tool version now is 1.8.4, I found no version newer than this.
And my beego version is 1.8.3
I have removed beego/bee and astaxie/beego, and then reinstalled them using:
go get github.com/astaxie/beego
go get github.com/beego/bee,
But nothing improved....

Hmm.. maybe you need to regenerate comments controller? Make some change in your controller file?

in beego 1.8.4 another parameter was added to ControllerComments. You can add nil to last item and then try to regenerate the source. Which version of beego did you upgrade from?

I'v no idea which version i used before...
You mean I add code in commentsRouter_xxx_controllers.go and commentsRouter_controllers.go?
Are these files not auto-generated?

And I tried to modify get to post in controller files, but no changes happend in commentsRouter_xxx_controllers.go

Yes, do it manually one time to make sure it compiles. Then go to your xxx controller file and do some minor change (so beego will detect it needs to regenerate)

After I add nil to last item in ControllerComments, it shows [parser.go:117] Invalid @Param format. Needs at least 4 parameters, stack shows below:
2017/05/21 15:58:45 [E] [parser.go:117] Invalid @Param format. Needs at least 4 parameters
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/astaxie/beego.parseComment(0xc4202bb9c0, 0x6, 0x8, 0xc42032c770, 0xe, 0xc42032c770)
/gowork/src/github.com/astaxie/beego/parser.go:210 +0xd5f
github.com/astaxie/beego.parserComments(0xc4202c2060, 0xc42032c770, 0xe, 0x1590883, 0x1e, 0x0, 0x0)
/gowork/src/github.com/astaxie/beego/parser.go:117 +0x85
github.com/astaxie/beego.parserPkg(0xc4201132c0, 0x39, 0x1590883, 0x1e, 0x19be500, 0x0)
/gowork/src/github.com/astaxie/beego/parser.go:89 +0x513
github.com/astaxie/beego.(ControllerRegister).Include(0xc4200ab3f0, 0xc42016fd10, 0x1, 0x1)
/gowork/src/github.com/astaxie/beego/router.go:244 +0x7f8
github.com/astaxie/beego.(
Namespace).Include(0xc420177420, 0xc42016fd10, 0x1, 0x1, 0xc420177420)
/gowork/src/github.com/astaxie/beego/namespace.go:186 +0x4d
github.com/astaxie/beego.NSInclude.func1(0xc420177420)
/gowork/src/github.com/astaxie/beego/namespace.go:302 +0x46
github.com/astaxie/beego.NewNamespace(0x1694112, 0x5, 0xc42008e520, 0x1, 0x1, 0x1)
/gowork/src/github.com/astaxie/beego/namespace.go:42 +0xab
github.com/astaxie/beego.NSNamespace.func1(0xc4201773e0)
/gowork/src/github.com/astaxie/beego/namespace.go:386 +0x52
github.com/astaxie/beego.NewNamespace(0x1692a0c, 0x3, 0xc4201abef0, 0xd, 0xd, 0xc4201a0240)
/gowork/src/github.com/astaxie/beego/namespace.go:42 +0xab
xxx/routers.init.4()
/xxx/routers/router.go:92 +0xd8a
xxx/routers.init()
/xxxr/routers/router.go:95 +0x98
main.init()
/xxx/main.go:32 +0x58

It fixed after i modified comments of method in controller.
Now routers/comments_controller.go can be generated correctly, and it runs ok!
Thanks very much for help!

Is that not a bug?I got this error too.
I add "MethodParams: nil" to commentsRouter_controllers.go and it's was still error.
After I change controllers,commentsRouter_controllers has no changes

@qichengzx please delete commentsRouter_controllers.go and generate again

@astaxie 删掉了,并没有重新生成,我再研究下。多谢。

@qichengzx 路由没有自动生成?你是不是在dev模式?

@astaxie 不好意思刚看到。嗯,在dev模式。

我知道了是什么引发了这个问题,在以前的controller里的@param参数只有一个@Param body”。所以会报“[E] [parser.go:117] Invalid @Param format. Needs at least 4 parameters”

I know what caused this problem, the @param parameter in the previous controller only has a "@Param body". So will be reported "[E] [parser.go: 117] Invalid @Param format. Needs at least 4 parameters"

routers/commentsRouter_controllers.go:70:13: unknown field 'Filters' in struct literal of type beego.ControllerComments

Was this page helpful?
0 / 5 - 0 ratings

Related issues

natemara picture natemara  ·  4Comments

jniltinho picture jniltinho  ·  4Comments

Rushit picture Rushit  ·  3Comments

astaxie picture astaxie  ·  4Comments

osavchenko picture osavchenko  ·  4Comments