-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
241 lines (228 loc) · 5.91 KB
/
options.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package mongoleaf
import (
"encoding/json"
"go.mongodb.org/mongo-driver/mongo/options"
)
var option optionType
type optionType struct {
Database OptDatabase
}
type OptDatabase struct {
Colletion OptColletion
}
type OptColletion struct {
Indexes OptIndexes
}
type OptIndexes struct{}
//client options
func (_ optionType) listDatabase(option string) (options.ListDatabasesOptions, error) {
var op options.ListDatabasesOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.ListDatabasesOptions{}, err
}
return op, nil
}
//db options
func (_ OptDatabase) aggregate(option string) (options.AggregateOptions, error) {
var op options.AggregateOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.AggregateOptions{}, err
}
return op, nil
}
func (_ OptDatabase) createCollection(option string) (options.CreateCollectionOptions, error) {
var op options.CreateCollectionOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.CreateCollectionOptions{}, err
}
return op, nil
}
func (_ OptDatabase) createView(option string) (options.CreateViewOptions, error) {
var op options.CreateViewOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.CreateViewOptions{}, err
}
return op, nil
}
func (_ OptDatabase) listCollections(option string) (options.ListCollectionsOptions, error) {
var op options.ListCollectionsOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.ListCollectionsOptions{}, err
}
return op, nil
}
func (_ OptDatabase) session(option string) (options.SessionOptions, error) {
var op options.SessionOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.SessionOptions{}, err
}
return op, nil
}
func (_ OptDatabase) runCmd(option string) (options.RunCmdOptions, error) {
var op options.RunCmdOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.RunCmdOptions{}, err
}
return op, nil
}
//col options
func (_ OptColletion) update(option string) (options.UpdateOptions, error) {
var op options.UpdateOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.UpdateOptions{}, err
}
return op, nil
}
func (_ OptColletion) delete(option string) (options.DeleteOptions, error) {
var op options.DeleteOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.DeleteOptions{}, err
}
return op, nil
}
func (_ OptColletion) insertMany(option string) (options.InsertManyOptions, error) {
var op options.InsertManyOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.InsertManyOptions{}, err
}
return op, nil
}
func (_ OptColletion) insertOne(option string) (options.InsertOneOptions, error) {
var op options.InsertOneOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.InsertOneOptions{}, err
}
return op, nil
}
func (_ OptColletion) find(option string) (options.FindOptions, error) {
var op options.FindOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.FindOptions{}, err
}
return op, nil
}
func (_ OptColletion) findOne(option string) (options.FindOneOptions, error) {
var op options.FindOneOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.FindOneOptions{}, err
}
return op, nil
}
func (_ OptColletion) countDocuments(option string) (options.CountOptions, error) {
var op options.CountOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.CountOptions{}, err
}
return op, nil
}
func (_ OptColletion) distinct(option string) (options.DistinctOptions, error) {
var op options.DistinctOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.DistinctOptions{}, err
}
return op, nil
}
func (_ OptColletion) findOneAndUpdate(option string) (options.FindOneAndUpdateOptions, error) {
var op options.FindOneAndUpdateOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.FindOneAndUpdateOptions{}, err
}
return op, nil
}
func (_ OptColletion) findOneAndReplace(option string) (options.FindOneAndReplaceOptions, error) {
var op options.FindOneAndReplaceOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.FindOneAndReplaceOptions{}, err
}
return op, nil
}
func (_ OptColletion) findOneAndDelete(option string) (options.FindOneAndDeleteOptions, error) {
var op options.FindOneAndDeleteOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.FindOneAndDeleteOptions{}, err
}
return op, nil
}
func (_ OptIndexes) create(option string) (options.CreateIndexesOptions, error) {
var op options.CreateIndexesOptions
if option == "" || option == "{}" {
return op, nil
}
err := json.Unmarshal([]byte(option), &op)
if err != nil {
return options.CreateIndexesOptions{}, err
}
return op, nil
}