I am trying to encode some JSON for a REST api, everything works fine except for some errors. For example, using this structure:
type TemplateResponse struct {
Message string
Error error
Template Template
}
Encoded by this data:
res := TemplateResponse{"Template not found.", fmt.Errorf("There is no template on this host with the name " + vars["name"]), Template{}}
json.NewEncoder(w).Encode(res)
Return:
{
"Message": "Template not found.",
"Error": {},
"Template": {
"Name": "",
"Disabled": false,
"Path": "",
"Version": ""
}
}
I get this, it would seem, randomly in my application, where the types of "errors" are returned as empty. Any ideas?
Thank!
source
share