Does anyone know how to set the tag names for multilevel structs? The top level tag-names of the struct works ok, but all sublevels tag names have the same name as in the struct. Trying to set all tag-name to lowercase.
The code can be run here:
package main
import (
"encoding/json"
"log"
)
type Source struct {
Pointer string `json:pointer,omitempty"`
Parameter string `json:parameter,omitempty"`
}
type Error struct {
Status int `json:"status,omitempty"`
Source *Source `json:"source,omitempty"`
Title string `json:"title,omitempty"`
Detail string `json:"detail,omitempty"`
}
type Errors struct {
Errors *[]Error `json:"errors"`
}
func main() {
errors := new(Errors)
errors.Errors = new([]Error)
error := new(Error)
error.Source = new(Source)
error.Source.Pointer = "pointer"
error.Status = 401
error.Title = "title"
error.Detail = "detail"
*errors.Errors = append(*(errors.Errors), *error)
response, _ := json.Marshal(errors)
log.Println("response", string(response))
}
Output:
{
"errors": [
{
"status": 400,
"source": {
"Pointer": "pointer",
"Parameter": ""
},
"title": "title",
"detail": "detail"
}
]
}