Skip to content

Commit 46d3ced

Browse files
authored
Added support for implementing the Linkable and Metable interface on collections (slices) being Marshalled. (#94)
1 parent cf83b97 commit 46d3ced

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

response.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,25 @@ func Marshal(models interface{}) (Payloader, error) {
8484
if err != nil {
8585
return nil, err
8686
}
87-
return marshalMany(m)
87+
88+
payload, err := marshalMany(m)
89+
if err != nil {
90+
return nil, err
91+
}
92+
93+
if linkableModels, isLinkable := models.(Linkable); isLinkable {
94+
jl := linkableModels.JSONAPILinks()
95+
if er := jl.validate(); er != nil {
96+
return nil, er
97+
}
98+
payload.Links = linkableModels.JSONAPILinks()
99+
}
100+
101+
if metableModels, ok := models.(Metable); ok {
102+
payload.Meta = metableModels.JSONAPIMeta()
103+
}
104+
105+
return payload, nil
88106
case reflect.Ptr:
89107
// Check that the pointer was to a struct
90108
if reflect.Indirect(vals).Kind() != reflect.Struct {

0 commit comments

Comments
 (0)