-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdocument.go
40 lines (31 loc) · 848 Bytes
/
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
package iamgo
import (
"encoding/json"
"github.com/liamg/jfather"
)
type Document struct {
inner innerDocument
r Range
}
type innerDocument struct {
Version String `json:"Version"`
Id String `json:"Id,omitempty"`
Statement Statements `json:"Statement"`
}
func (d *Document) UnmarshalJSONWithMetadata(node jfather.Node) error {
d.r.StartLine = node.Range().Start.Line
d.r.EndLine = node.Range().End.Line
return node.Decode(&d.inner)
}
func (d *Document) Version() (string, Range) {
return d.inner.Version.inner, d.inner.Version.r
}
func (d *Document) ID() (string, Range) {
return d.inner.Id.inner, d.inner.Id.r
}
func (d *Document) Statements() ([]Statement, Range) {
return d.inner.Statement.inner, d.inner.Statement.r
}
func (d *Document) MarshalJSON() ([]byte, error) {
return json.Marshal(d.inner)
}