/
json.go
53 lines (44 loc) · 1.07 KB
/
json.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
package models
// JSON API Specification - Document Structure
// http://jsonapi.org/format/1.0/#document-structure
type Response struct {
Data ResponseData `json:"data"`
Meta
}
type ResponseData struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes interface{} `json:"attributes"`
Relationships interface{} `json:"relationships,omitempty"`
Links Links `json:"links,omitempty"`
Meta
}
type Relationship struct {
Links Links `json:"links,omitempty"`
Data ResponseData `json:"data,omitempty"`
Meta
}
type Links struct {
Self string `json:"self,omitempty"`
Related string `json:"related,omitempty"`
}
type Link struct {
Href string `json:"href"`
Meta
}
type Meta struct {
Meta interface{} `json:"meta,omitempty"`
}
func NewResponse(id, resourceType, selfUri string, attributes interface{}) Response {
return Response{
Data: ResponseData{
ID: id,
Type: resourceType,
Attributes: attributes,
Links: Links{
Self: selfUri,
},
},
}
}
var EmptyRespose = Response{}