I am really new to Golang and I am trying to parse values to my ErrorMessage struct when an error occurs.
I have this struct:
type ErrorMessage struct {
Errors []struct {
Code string `json:"code"`
Message string `json:"message"`
Field string `json:"field,omitempty"`
} `json:"errors"`
Meta struct {
Status string `json:"status"`
} `json:"meta"`
}
Which is mapped to display JSON like this:
{
"errors": [
{
"code": "short-code",
"message": "Wow, such bad!"
},
{
"code": "other-code",
"message": "OMG, very error!",
"field": "This is the field"
}
],
"meta": {
"status": "error"
}
}
However I cannot work out how to parse the values from my controller into this Struct. For a basic Struct I understand and had something like this:
e := models.ErrorMessage{"Error", "404", "Field Missing"}
How would use a line similar to the above but for the more complicated Struct?