-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelationships_object.go
More file actions
34 lines (27 loc) · 893 Bytes
/
relationships_object.go
File metadata and controls
34 lines (27 loc) · 893 Bytes
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
package jsonapi
import "encoding/json"
// RelationshipsObject represents a collection of multiple Relationships. Relationships should
// be used to represent all the numerous relationships for an object.
type RelationshipsObject interface {
Append(string, Relationship)
}
// Relationship represents something that can append resource identifiers to represent
// a particular relationship. The Relationship only ever represents a single relationship.
type Relationship interface {
Append(ResourceIdentifier)
}
func newRelationships() RelationshipsObject {
return &relations{
storage: make(map[string]Relationship),
}
}
type relations struct {
storage map[string]Relationship
}
func (rels *relations) MarshalJSON() ([]byte, error) {
return json.Marshal(rels.storage)
}
func (rel *relations) Append(name string, relManager Relationship) {
rel.storage[name] = relManager
return
}