forked from crestonbunch/godata
-
Notifications
You must be signed in to change notification settings - Fork 1
/
request_model.go
138 lines (113 loc) · 3.11 KB
/
request_model.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package godata
type GoDataIdentifier map[string]string
const (
RequestKindUnknown int = iota
RequestKindMetadata
RequestKindService
RequestKindEntity
RequestKindCollection
RequestKindSingleton
RequestKindProperty
RequestKindPropertyValue
RequestKindRef
RequestKindCount
)
const (
SemanticTypeUnknown int = iota
SemanticTypeEntity
SemanticTypeEntitySet
SemanticTypeDerivedEntity
SemanticTypeAction
SemanticTypeFunction
SemanticTypeProperty
SemanticTypePropertyValue
SemanticTypeRef
SemanticTypeCount
SemanticTypeMetadata
)
type GoDataRequest struct {
FirstSegment *GoDataSegment
LastSegment *GoDataSegment
Query *GoDataQuery
RequestKind int
}
// Represents a segment (slash-separated) part of the URI path. Each segment
// has a link to the next segment (the last segment precedes nil).
type GoDataSegment struct {
// The raw segment parsed from the URI
RawValue string
// The kind of resource being pointed at by this segment
SemanticType int
// A pointer to the metadata type this object represents, as defined by a
// particular service
SemanticReference interface{}
// The name of the entity, type, collection, etc.
Name string
// map[string]string of identifiers passed to this segment. If the identifier
// is not key/value pair(s), then all values will be nil. If there is no
// identifier, it will be nil.
Identifier *GoDataIdentifier
// The next segment in the path.
Next *GoDataSegment
// The previous segment in the path.
Prev *GoDataSegment
}
type GoDataQuery struct {
Filter *GoDataFilterQuery
Apply *GoDataApplyQuery
Expand *GoDataExpandQuery
Select *GoDataSelectQuery
OrderBy *GoDataOrderByQuery
Top *GoDataTopQuery
Skip *GoDataSkipQuery
Count *GoDataCountQuery
InlineCount *GoDataInlineCountQuery
Search *GoDataSearchQuery
Format *GoDataFormatQuery
}
// Stores a parsed version of the filter query string. Can be used by
// providers to apply the filter based on their own implementation. The filter
// is stored as a parse tree that can be traversed.
type GoDataFilterQuery struct {
Tree *ParseNode
}
type GoDataApplyQuery string
type GoDataExpandQuery struct {
ExpandItems []*ExpandItem
}
type GoDataSelectQuery struct {
SelectItems []*SelectItem
}
type GoDataOrderByQuery struct {
OrderByItems []*OrderByItem
}
type GoDataTopQuery int
type GoDataSkipQuery int
type GoDataCountQuery bool
type GoDataInlineCountQuery string
type GoDataSearchQuery struct {
Tree *ParseNode
}
type GoDataFormatQuery struct {
}
// Check if this identifier has more than one key/value pair.
func (id *GoDataIdentifier) HasMultiple() bool {
count := 0
for range map[string]string(*id) {
count++
}
return count > 1
}
// Return the first key in the map. This is how you should get the identifier
// for single values, e.g. when the path is Employee(1), etc.
func (id *GoDataIdentifier) Get() string {
for k, _ := range map[string]string(*id) {
return k
}
return ""
}
// Return a specific value for a specific key.
func (id *GoDataIdentifier) GetKey(key string) (string, bool) {
v, ok := map[string]string(*id)[key]
return v, ok
}