我在 Beego 應用程序上創建端點時遇到問題因此,我只是將一些對象信息放在返回的 JSON 上:// GetOne ...// @Title GetOne// @Description get Migration by id// @Param id path string true "The key for staticblock"// @Success 200 {object} models.Migration// @Failure 403 :id is empty// @router /:id [get]func (c *MigrationController) GetOne() { val, err := mg.Data["json"] = map[string]string{ "MigrationId": c.MigrationId "Status": c.Status "Created": c.Created "Updated": c.Updated } if err != nil { log.Debug("Fail - GetOne: %v", err) } else { mg.ServeJSON() }當我嘗試調用端點時,我得到了這個Handler crashed with error can't find templatefile in the path:views/migrationcontroller/getone.tpl我沒有在整個代碼中的任何地方使用這些模板......我對這個框架不熟悉,有人可以幫助我嗎?更新:這是一個遺留代碼,有太多問題,團隊決定在我仍在處理這個項目時不修復它因此,我無法說出修復后的代碼會是什么樣子
1 回答

Smart貓小萌
TA貢獻1911條經驗 獲得超7個贊
您應該將 ServeJSON() 與當前控制器一起使用。
func (c *MigrationController) GetOne() {
defer c.ServeJSON()
...
}
- 1 回答
- 0 關注
- 239 瀏覽
添加回答
舉報
0/150
提交
取消