Beego 找不到控制器

use*_*232 1 rest frameworks go beego

我正在研究 beego 应用程序。我试图在两台不同的机器上运行相同的代码。两者都是ubuntu。在一台机器上,它运行没有任何问题,但在另一台机器上我得到了以下错误日志。我对两者都有相同的文件组织,您认为为什么会发生这种情况?

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)
Run Code Online (Sandbox Code Playgroud)

偶控制器:

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()
}
Run Code Online (Sandbox Code Playgroud)

use*_*232 5

我发现了问题。Beego 在我安装机器之间发布了新版本。我以为它看不到整个控制器,但它只是函数的名称。

在新版本中:

serveJson() -> serveJSON()
Run Code Online (Sandbox Code Playgroud)

配置也改变了。

Beego.HttpPort -> beego.BConfig.Listen.HTTPPort
Run Code Online (Sandbox Code Playgroud)

  • -u 在 go get 之后更新您现有的依赖项。因此我上面的评论。 (2认同)