Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Slemgrim 2017-07-10 22:16:45 +02:00
commit f0b268e046
1 changed files with 19 additions and 1 deletions

View File

@ -84,7 +84,25 @@ func Marshal(models interface{}) (Payloader, error) {
if err != nil { if err != nil {
return nil, err 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: case reflect.Ptr:
// Check that the pointer was to a struct // Check that the pointer was to a struct
if reflect.Indirect(vals).Kind() != reflect.Struct { if reflect.Indirect(vals).Kind() != reflect.Struct {