英文:
Beego Cannot Find Controller
问题
我正在使用beego应用程序。我试图在两台不同的机器上运行相同的代码。两台机器都是Ubuntu系统。在一台机器上,它可以正常运行,但在另一台机器上,我得到了以下错误日志。我对两台机器的文件组织方式是相同的,你认为可能是什么原因导致这种情况发生?
controllers/EventController.go:18: this.ServeJson未定义(*EventController类型没有ServeJson字段或方法)
controllers/EventController.go:24: this.ServeJson未定义(*EventController类型没有ServeJson字段或方法)
controllers/EventController.go:30: this.ServeJson未定义(*EventController类型没有ServeJson字段或方法)
controllers/default.go:14: c.TplNames未定义(*MainController类型没有TplNames字段或方法)
EventController代码如下:
package controllers
import (
"github.com/astaxie/beego"
"solardatabase/models"
"solardatabase/dao"
"solardatabase/services"
)
type EventController struct {
beego.Controller
}
func (this *EventController) ListEvents() {
res := struct{ Tasks []*models.Event }{dao.GetAllEvents()}
this.Data["json"] = res
this.ServeJson()
}
func (this *EventController) ListEventsByRange() {
request, _ := models.CreateEventByTimeRangeRequest(this.Ctx.Input)
this.Data["json"] = dao.EventsByTimeRange(request)
this.ServeJson()
}
func (this *EventController) TemporalQuery() {
request, _ := models.CreateTemporalRequest(this.Ctx.Input)
this.Data["json"] = services.EventsByTimeFilter(request)
this.ServeJson()
}
英文:
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?
controllers/EventController.go:18: this.ServeJson undefined (type *EventController has no field or method ServeJson)
controllers/EventController.go:24: this.ServeJson undefined (type *EventController has no field or method ServeJson)
controllers/EventController.go:30: this.ServeJson undefined (type *EventController has no field or method ServeJson)
controllers/default.go:14: c.TplNames undefined (type *MainController has no field or method TplNames)
Even controller:
package controllers
import (
"github.com/astaxie/beego"
"solardatabase/models"
"solardatabase/dao"
"solardatabase/services"
)
type EventController struct {
beego.Controller
}
func (this *EventController) ListEvents() {
res := struct{ Tasks []*models.Event }{dao.GetAllEvents()}
this.Data["json"] = res
this.ServeJson()
}
func (this *EventController) ListEventsByRange() {
request, _ := models.CreateEventByTimeRangeRequest(this.Ctx.Input)
this.Data["json"] = dao.EventsByTimeRange(request)
this.ServeJson()
}
func (this *EventController) TemporalQuery() {
request, _ := models.CreateTemporalRequest(this.Ctx.Input)
this.Data["json"] = services.EventsByTimeFilter(request)
this.ServeJson()
}
答案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:
serveJson() -> serveJSON()
Config also changed.
Beego.HttpPort -> beego.BConfig.Listen.HTTPPort
答案2
得分: 1
Beego版本1.11.1
这是区分大小写的。
将
this.ServeJson()
改为
this.ServeJSON()
英文:
Beego version 1.11.1
This is case sensitive.
Change
this.ServeJson()
to
this.ServeJSON()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论