Beego无法找到控制器。

huangapple go评论111阅读模式
英文:

Beego Cannot Find Controller

问题

我正在使用beego应用程序。我试图在两台不同的机器上运行相同的代码。两台机器都是Ubuntu系统。在一台机器上,它可以正常运行,但在另一台机器上,我得到了以下错误日志。我对两台机器的文件组织方式是相同的,你认为可能是什么原因导致这种情况发生?

  1. controllers/EventController.go:18: this.ServeJson未定义(*EventController类型没有ServeJson字段或方法)
  2. controllers/EventController.go:24: this.ServeJson未定义(*EventController类型没有ServeJson字段或方法)
  3. controllers/EventController.go:30: this.ServeJson未定义(*EventController类型没有ServeJson字段或方法)
  4. controllers/default.go:14: c.TplNames未定义(*MainController类型没有TplNames字段或方法)

EventController代码如下:

  1. package controllers
  2. import (
  3. "github.com/astaxie/beego"
  4. "solardatabase/models"
  5. "solardatabase/dao"
  6. "solardatabase/services"
  7. )
  8. type EventController struct {
  9. beego.Controller
  10. }
  11. func (this *EventController) ListEvents() {
  12. res := struct{ Tasks []*models.Event }{dao.GetAllEvents()}
  13. this.Data["json"] = res
  14. this.ServeJson()
  15. }
  16. func (this *EventController) ListEventsByRange() {
  17. request, _ := models.CreateEventByTimeRangeRequest(this.Ctx.Input)
  18. this.Data["json"] = dao.EventsByTimeRange(request)
  19. this.ServeJson()
  20. }
  21. func (this *EventController) TemporalQuery() {
  22. request, _ := models.CreateTemporalRequest(this.Ctx.Input)
  23. this.Data["json"] = services.EventsByTimeFilter(request)
  24. this.ServeJson()
  25. }
英文:

I am working on beego application. I am trying to run the same code in two different machine. Both are ubuntu. In one machine, it runs without any problem but in other I got following error log. I have the same file organization for both, why do you think this might be happening?

  1. controllers/EventController.go:18: this.ServeJson undefined (type *EventController has no field or method ServeJson)
  2. controllers/EventController.go:24: this.ServeJson undefined (type *EventController has no field or method ServeJson)
  3. controllers/EventController.go:30: this.ServeJson undefined (type *EventController has no field or method ServeJson)
  4. controllers/default.go:14: c.TplNames undefined (type *MainController has no field or method TplNames)

Even controller:

  1. package controllers
  2. import (
  3. "github.com/astaxie/beego"
  4. "solardatabase/models"
  5. "solardatabase/dao"
  6. "solardatabase/services"
  7. )
  8. type EventController struct {
  9. beego.Controller
  10. }
  11. func (this *EventController) ListEvents() {
  12. res := struct{ Tasks []*models.Event }{dao.GetAllEvents()}
  13. this.Data["json"] = res
  14. this.ServeJson()
  15. }
  16. func (this *EventController) ListEventsByRange() {
  17. request, _ := models.CreateEventByTimeRangeRequest(this.Ctx.Input)
  18. this.Data["json"] = dao.EventsByTimeRange(request)
  19. this.ServeJson()
  20. }
  21. func (this *EventController) TemporalQuery() {
  22. request, _ := models.CreateTemporalRequest(this.Ctx.Input)
  23. this.Data["json"] = services.EventsByTimeFilter(request)
  24. this.ServeJson()
  25. }

答案1

得分: 5

我找到了问题。在我安装机器之间,Beego发布了新版本。我以为它无法看到整个控制器,但实际上只是函数的名称有所改变。

在新版本中:

serveJson() -> serveJSON()

配置也有所改变。

Beego.HttpPort -> beego.BConfig.Listen.HTTPPort

英文:

I found the problem. Beego released new version between my installation of the machines. I thought it cannot see the whole controller but It was only the name of function.

In new version:

  1. serveJson() -> serveJSON()

Config also changed.

  1. Beego.HttpPort -> beego.BConfig.Listen.HTTPPort

答案2

得分: 1

Beego版本1.11.1

这是区分大小写的。

  1. this.ServeJson()

改为

  1. this.ServeJSON()
英文:

Beego version 1.11.1

This is case sensitive.

Change

  1. this.ServeJson()

to

  1. this.ServeJSON()

huangapple
  • 本文由 发表于 2016年1月28日 03:37:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/35046511.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定