-
Notifications
You must be signed in to change notification settings - Fork 0
/
relationship.go
56 lines (48 loc) · 1.57 KB
/
relationship.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package jsonapi
// Relationships is a map of JSON:API relationship objects.
type Relationships map[string]interface{}
// RelationshipLink is a JSON:API relationship links object.
// See https://jsonapi.org/format/#document-resource-object-related-resource-links.
type RelationshipLink struct {
Self string `json:"self,omitempty"`
Related string `json:"related,omitempty"`
}
type relationship struct {
Links *RelationshipLink `json:"links,omitempty"`
Meta *Meta `json:"meta,omitempty"`
}
// Relationship struct { is a JSON:API relationship object.
// See https://jsonapi.org/format/#document-resource-object-relationships.
type Relationship struct {
Data *Resource `json:"data"`
relationship
}
// CompoundRelationship is a JSON:API compound relationship object.
// See https://jsonapi.org/format/#document-resource-object-relationships.
type CompoundRelationship struct {
Data []*Resource `json:"data"`
relationship
}
// NewRelationship generates a new JSON:API relationship object.
func NewRelationship() *Relationship {
return &Relationship{
relationship: relationship{
// Links: &RelationshipLink{},
// Meta: &Meta{},
},
}
}
// AddResource adds a new resource to an existing realationship.
func (r *Relationship) AddResource(resource *Resource) {
r.Data = resource
}
// NewCompoundRelationship generates a new JSON:API compound relationship object.
func NewCompoundRelationship() *CompoundRelationship {
return &CompoundRelationship{
Data: []*Resource{},
relationship: relationship{
// Links: &RelationshipLink{},
// Meta: &Meta{},
},
}
}