Added support for implementing the Linkable and Metable interface on collections (slices) being Marshalled. (#94)

This commit is contained in:
Aren Patel 2017-07-07 17:58:51 -07:00 committed by GitHub
parent cf83b97b3d
commit 46d3ced043
1 changed files with 19 additions and 1 deletions

View File

@ -84,7 +84,25 @@ func Marshal(models interface{}) (Payloader, error) {
if err != nil {
return nil, err
}
return marshalMany(m)
payload, err := marshalMany(m)
if err != nil {
return nil, err
}
if linkableModels, isLinkable := models.(Linkable); isLinkable {
jl := linkableModels.JSONAPILinks()
if er := jl.validate(); er != nil {
return nil, er
}
payload.Links = linkableModels.JSONAPILinks()
}
if metableModels, ok := models.(Metable); ok {
payload.Meta = metableModels.JSONAPIMeta()
}
return payload, nil
case reflect.Ptr:
// Check that the pointer was to a struct
if reflect.Indirect(vals).Kind() != reflect.Struct {