-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument.go
71 lines (63 loc) · 1.6 KB
/
document.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
package jsonapi
// Document is a JSON:API document top-level object.
// See https://jsonapi.org/format/#document-top-level.
type Document struct {
Data *Resource `json:"data,omitempty"`
document
}
// NewDocumentParams are the parameters describing a top-level document.
type NewDocumentParams struct {
documentParams
}
// NewDocument generates a new top-level document object.
func NewDocument(p *NewDocumentParams) *Document {
d := document{
JSONAPI: &Information{
Version: "1.0",
},
}
if p != nil {
d.Links = p.Links
d.Meta = p.Meta
}
return &Document{
document: d,
}
}
// CompoundDocument represents a compound document's top-level object.
// See https://jsonapi.org/format/#document-compound-documents.
type CompoundDocument struct {
Data []*Resource `json:"data"`
document
}
// NewCompoundDocumentParams are the parameters describing a new compound top-level document.
type NewCompoundDocumentParams struct {
documentParams
}
// NewCompoundDocument generates a new compound top-level document object.
func NewCompoundDocument(p *NewCompoundDocumentParams) *CompoundDocument {
d := document{
JSONAPI: &Information{
Version: "1.0",
},
}
if p != nil {
d.Links = p.Links
d.Meta = p.Meta
}
return &CompoundDocument{
Data: []*Resource{},
document: d,
}
}
type document struct {
JSONAPI *Information `json:"jsonapi,omitempty"`
Meta *Meta `json:"meta,omitempty"`
Links *Links `json:"links,omitempty"`
Errors []Error `json:"errors,omitempty"`
Included []*Resource `json:"included,omitempty"`
}
type documentParams struct {
Links *Links
Meta *Meta
}