-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodes.go
More file actions
49 lines (39 loc) · 1.08 KB
/
nodes.go
File metadata and controls
49 lines (39 loc) · 1.08 KB
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
package gofieldselect
var (
_ Node = new(Identifiers)
_ Node = new(AllIdentifiers)
)
type (
// Node is the top level of the field selection.
Node interface {
// SelectField method to indicate if the field is selected.
SelectField(fieldName string) (Identifier, bool)
node()
}
// Identifiers is the node with the list of fields that should be selected.
Identifiers []Identifier
// AllIdentifiers is the Node to indicate that every field should be selected.
AllIdentifiers struct{}
// Identifier holder that indicates the JSON field name and the children selection for that field
// E.g. `name` or `address(street,number)`.
Identifier struct {
Value string
Child Node
}
)
func (is Identifiers) SelectField(fieldName string) (Identifier, bool) {
for _, i := range is {
if i.Value == fieldName {
return i, true
}
}
return Identifier{}, false
}
func (is Identifiers) node() {}
func (a AllIdentifiers) SelectField(fieldName string) (Identifier, bool) {
return Identifier{
Value: fieldName,
Child: AllIdentifiers{},
}, true
}
func (a AllIdentifiers) node() {}