-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Description
Hi!
I could not find a way to easily to return a response with top-level custom metadata, i.e.
{
"data": ...
"meta": "my data"
}
but only found a way to add metadata at the resource level, e.g.
{
"data": [
{
"meta": ...
}
]
}
I had to write the following helper function to achieve it. is there a better way?
import (
"encoding/json"
"github.com/manyminds/api2go/jsonapi"
)
func MarshalWithMeta(data interface{}, meta map[string]interface{}) ([]byte, error) {
document, err := jsonapi.MarshalToStruct(data, nil)
if err != nil {
return nil, err
}
document.Meta = meta
bytesResponse, err := json.Marshal(document)
if err != nil {
return nil, err
}
return bytesResponse, nil
}
Metadata
Metadata
Assignees
Labels
No labels