-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_object.go
83 lines (67 loc) · 1.52 KB
/
resource_object.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package jsonapi
type DataSetter interface {
AppendData(ResourceObject)
}
type Includer interface {
AppendIncluded(ResourceObject)
}
type Document interface {
DataSetter
Includer
}
type ResourceObject interface {
ResourceIdentifier
SetID(string)
SetType(string)
GetAttributes() Attributes
GetRelationships() RelationshipsObject
}
type ResourceIdentifier interface {
GetID() string
GetType() string
}
type coreResourceObject struct {
ID string `json:"id,omitempty"`
Type string `json:"type"`
Attributes Attributes `json:"attributes,omitempty"`
Relationships RelationshipsObject `json:"relationships,omitempty"`
}
func newResourceObject() ResourceObject {
return &coreResourceObject{}
}
func (n *coreResourceObject) GetID() string {
return n.ID
}
func (n *coreResourceObject) SetID(id string) {
n.ID = id
return
}
func (n *coreResourceObject) GetType() string {
return n.Type
}
func (n *coreResourceObject) SetType(t string) {
n.Type = t
return
}
func (n *coreResourceObject) GetAttributes() Attributes {
if n.Attributes == nil {
n.Attributes = newAttributes()
}
return n.Attributes
}
func (n *coreResourceObject) GetRelationships() RelationshipsObject {
if n.Relationships == nil {
n.Relationships = newRelationships()
}
return n.Relationships
}
type coreResIdentifier struct {
ID string `json:"id"`
Type string `json:"type"`
}
func (n *coreResIdentifier) GetID() string {
return n.ID
}
func (n *coreResIdentifier) GetType() string {
return n.Type
}