I'm a newbie to beego trying to get a JSON response on a route.
I have a controller defined as such.
package controllers
import (
"github.com/astaxie/beego"
)
type ErrorController struct {
beego.Controller
}
type ErrorJson struct {
s string
d string
}
func (this *ErrorController) Get() {
var responseJson ErrorJson
responseJson = ErrorJson{
s: "asdf",
d: "qwer",
}
this.Data["json"] = responseJson
this.ServeJson()
}
My router is defined as
beego.Router("/api", &controllers.ErrorController{})
When I visit the route, I get an Empty JSON object without any properties.
{}
If I replace the json struct with a string, I get a response. So beego is aware of the controller and the method.
this.Data["json"] = "Hello World"
What am I doing wrong?