首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Beego找不到控制器

Beego找不到控制器
EN

Stack Overflow用户
提问于 2016-01-28 03:37:03
回答 2查看 1.8K关注 0票数 1

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

代码语言:javascript
复制
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)

偶数控制器:

代码语言:javascript
复制
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()
}
EN

回答 2

Stack Overflow用户

发布于 2016-01-28 14:10:02

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

在新版本中:

代码语言:javascript
复制
serveJson() -> serveJSON()

配置也发生了变化。

代码语言:javascript
复制
Beego.HttpPort -> beego.BConfig.Listen.HTTPPort
票数 5
EN

Stack Overflow用户

发布于 2019-02-08 11:56:47

Beego版本1.11.1

这是区分大小写的。

变化

代码语言:javascript
复制
this.ServeJson()

代码语言:javascript
复制
this.ServeJSON()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35046511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档