Repository navigation
Expand file tree
/
Copy pathinsert_append_delete_must.go
More file actions
245 lines (202 loc) · 8.6 KB
/
Copy pathinsert_append_delete_must.go
File metadata and controls
245 lines (202 loc) · 8.6 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
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
242
243
244
245
package jsonvalue
// ================ INSERT ================
// MustInserter is just like Inserter, but not returning sub-value or error.
type MustInserter interface {
// After completes the following operation of Insert(). It inserts value AFTER
// specified position.
//
// The last parameter identifies the position where a new JSON is inserted after,
// it should ba an integer, no matter signed or unsigned. If the position is
// zero or positive integer, it tells the index of an array. If the position
// is negative, it tells the backward index of an array.
//
// For example, 0 represents the first, and -2 represents the second last.
//
// After 结束并完成 Insert() 函数的后续插入操作,表示插入到指定位置的前面。
//
// 在 Before 函数的最后一个参数指定了被插入的 JSON 数组的位置,这个参数应当是一个整型
// (有无符号类型均可)。
// 如果这个值等于0或者正整数,那么它指定的是在 JSON 数组中的位置(从0开始)。如果这个值是负数,
// 那么它指定的是 JSON 数组中从最后一个位置开始算起的位置。
//
// 举例说明:0 表示第一个位置,而 -2 表示倒数第二个位置。
After(firstParam any, otherParams ...any)
// Before completes the following operation of Insert(). It inserts value BEFORE
// specified position.
//
// The last parameter identifies the position where a new JSON is inserted after,
// it should ba an integer, no matter signed or unsigned. If the position is
// zero or positive integer, it tells the index of an array. If the position
// is negative, it tells the backward index of an array.
//
// For example, 0 represents the first, and -2 represents the second last.
//
// Before 结束并完成 Insert() 函数的后续插入操作,表示插入到指定位置的后面。
//
// 在 Before 函数的最后一个参数指定了被插入的 JSON 数组的位置,这个参数应当是一个整型
// (有无符号类型均可)。
// 如果这个值等于0或者正整数,那么它指定的是在 JSON 数组中的位置(从0开始)。如果这个值是负数,
// 那么它指定的是 JSON 数组中从最后一个位置开始算起的位置。
//
// 举例说明:0 表示第一个位置,而 -2 表示倒数第二个位置。
Before(firstParam any, otherParams ...any)
}
type mInsert struct {
inserter Inserter
}
// MustInsert is just like Insert, but not returning sub-value or error.
func (v *V) MustInsert(child any) MustInserter {
ins := v.Insert(child)
return &mInsert{
inserter: ins,
}
}
// MustInsertString is just like InsertString, but not returning sub-value or error.
func (v *V) MustInsertString(s string) MustInserter {
return v.MustInsert(NewString(s))
}
// MustInsertBool is just like InsertBool, but not returning sub-value or error.
func (v *V) MustInsertBool(b bool) MustInserter {
return v.MustInsert(NewBool(b))
}
// MustInsertInt is just like InsertInt, but not returning sub-value or error.
func (v *V) MustInsertInt(i int) MustInserter {
return v.MustInsert(NewInt(i))
}
// MustInsertInt64 is just like InsertInt64, but not returning sub-value or error.
func (v *V) MustInsertInt64(i int64) MustInserter {
return v.MustInsert(NewInt64(i))
}
// MustInsertInt32 is just like InsertInt32, but not returning sub-value or error.
func (v *V) MustInsertInt32(i int32) MustInserter {
return v.MustInsert(NewInt32(i))
}
// MustInsertUint is just like InsertUint, but not returning sub-value or error.
func (v *V) MustInsertUint(u uint) MustInserter {
return v.MustInsert(NewUint(u))
}
// MustInsertUint64 is just like InsertUint64, but not returning sub-value or error.
func (v *V) MustInsertUint64(u uint64) MustInserter {
return v.MustInsert(NewUint64(u))
}
// MustInsertUint32 is just like InsertUint32, but not returning sub-value or error.
func (v *V) MustInsertUint32(u uint32) MustInserter {
return v.MustInsert(NewUint32(u))
}
// MustInsertFloat64 is just like InsertFloat64, but not returning sub-value or error.
func (v *V) MustInsertFloat64(f float64) MustInserter {
return v.MustInsert(NewFloat64(f))
}
// MustInsertFloat32 is just like InsertFloat32, but not returning sub-value or error.
func (v *V) MustInsertFloat32(f float32) MustInserter {
return v.MustInsert(NewFloat32(f))
}
// MustInsertNull is just like InsertNull, but not returning sub-value or error.
func (v *V) MustInsertNull() MustInserter {
return v.MustInsert(NewNull())
}
// MustInsertObject is just like InsertObject, but not returning sub-value or error.
func (v *V) MustInsertObject() MustInserter {
return v.MustInsert(NewObject())
}
// MustInsertArray is just like InsertArray, but not returning sub-value or error.
func (v *V) MustInsertArray() MustInserter {
return v.MustInsert(NewArray())
}
func (ins *mInsert) Before(firstParam any, otherParams ...any) {
_, _ = ins.inserter.Before(firstParam, otherParams...)
}
func (ins *mInsert) After(firstParam any, otherParams ...any) {
_, _ = ins.inserter.After(firstParam, otherParams...)
}
// ================ APPEND ================
// MustAppender is just like Appender, but not returning sub-value or error.
type MustAppender interface {
// InTheBeginning completes the following operation of Append().
//
// InTheBeginning 函数将 Append 函数指定的 JSON 值,添加到参数指定的数组的最前端
InTheBeginning(params ...any)
// InTheEnd completes the following operation of Append().
//
// InTheEnd 函数将 Append 函数指定的 JSON 值,添加到参数指定的数组的最后面
InTheEnd(params ...any)
}
type mAppender struct {
appender Appender
}
// Append starts appending a child JSON value to a JSON array.
//
// Append 开始将一个 JSON 值添加到一个数组中。需结合 InTheEnd() 和 InTheBeginning() 函数使用。
func (v *V) MustAppend(child any) MustAppender {
a := v.Append(child)
return &mAppender{
appender: a,
}
}
// MustAppendString is just like AppendString, but not returning sub-value or error.
func (v *V) MustAppendString(s string) MustAppender {
return v.MustAppend(NewString(s))
}
// MustAppendBytes is just like AppendBytes, but not returning sub-value or error.
func (v *V) MustAppendBytes(b []byte) MustAppender {
return v.MustAppend(NewBytes(b))
}
// MustAppendBool is just like AppendBool, but not returning sub-value or error.
func (v *V) MustAppendBool(b bool) MustAppender {
return v.MustAppend(NewBool(b))
}
// MustAppendInt is just like AppendInt, but not returning sub-value or error.
func (v *V) MustAppendInt(i int) MustAppender {
return v.MustAppend(NewInt(i))
}
// MustAppendInt64 is just like AppendInt64, but not returning sub-value or error.
func (v *V) MustAppendInt64(i int64) MustAppender {
return v.MustAppend(NewInt64(i))
}
// MustAppendInt32 is just like AppendInt32, but not returning sub-value or error.
func (v *V) MustAppendInt32(i int32) MustAppender {
return v.MustAppend(NewInt32(i))
}
// MustAppendUint is just like AppendUint, but not returning sub-value or error.
func (v *V) MustAppendUint(u uint) MustAppender {
return v.MustAppend(NewUint(u))
}
// MustAppendUint64 is just like AppendUint64, but not returning sub-value or error.
func (v *V) MustAppendUint64(u uint64) MustAppender {
return v.MustAppend(NewUint64(u))
}
// MustAppendUint32 is just like AppendUint32, but not returning sub-value or error.
func (v *V) MustAppendUint32(u uint32) MustAppender {
return v.MustAppend(NewUint32(u))
}
// MustAppendFloat64 is just like AppendFloat64, but not returning sub-value or error.
func (v *V) MustAppendFloat64(f float64) MustAppender {
return v.MustAppend(NewFloat64(f))
}
// MustAppendFloat32 is just like AppendFloat32, but not returning sub-value or error.
func (v *V) MustAppendFloat32(f float32) MustAppender {
return v.MustAppend(NewFloat32(f))
}
// MustAppendNull is just like AppendNull, but not returning sub-value or error.
func (v *V) MustAppendNull() MustAppender {
return v.MustAppend(NewNull())
}
// MustAppendObject is just like AppendObject, but not returning sub-value or error.
func (v *V) MustAppendObject() MustAppender {
return v.MustAppend(NewObject())
}
// MustAppendArray is just like AppendArray, but not returning sub-value or error.
func (v *V) MustAppendArray() MustAppender {
return v.MustAppend(NewArray())
}
func (apd *mAppender) InTheBeginning(params ...any) {
_, _ = apd.appender.InTheBeginning(params...)
}
func (apd *mAppender) InTheEnd(params ...any) {
_, _ = apd.appender.InTheEnd(params...)
}
// ================ DELETE ================
// MustDelete is just like Delete, but not returning error.
func (v *V) MustDelete(firstParam any, otherParams ...any) {
_ = v.Delete(firstParam, otherParams...)
}