Guilherme
Guilherme

Reputation: 1835

Beego endpoint can't find templatefile... but i'm not using template

I'm having trouble to create a endpoint on a Beego application

So, I just put some object information on the returned 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()
    }

When I tried to call the endpoint, I get this

Handler crashed with error can't find templatefile in the path:views/migrationcontroller/getone.tpl

I'm not using these templates anywhere in the whole code...

I'm not familiar with this framework, someone can help me?


update:

This was a legacy code, with too many issues, the team decided to not fix that at the time I was still working on this project Therefore, I'm not able to tell what the fixed code would look like

Upvotes: 1

Views: 1355

Answers (1)

ahmetlutfu
ahmetlutfu

Reputation: 325

You should use ServeJSON() with current controller.

func (c *MigrationController) GetOne() {
     defer c.ServeJSON()
     ...
}

Upvotes: 2

Related Questions