-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpaws.go
More file actions
319 lines (273 loc) · 6.64 KB
/
paws.go
File metadata and controls
319 lines (273 loc) · 6.64 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// Package paws provides some helper functions for gopher's developing experience.
package paws
import "time"
// String returns a new pointer of given s string.
func String(s string) *string { return &s }
// MustString returns a string value of pointer p, if p is not nil.
// s is returned, if p is nil.
func MustString(p *string, s string) string {
if p != nil {
return *p
}
return s
}
// Z2NString returns a new pointer of given s string.
// If s is zero value, it returns nil.
func Z2NString(s string) *string {
if s == "" {
return nil
}
return &s
}
// Bool returns a new pointer of given b bool.
func Bool(b bool) *bool { return &b }
// MustBool returns a bool value of pointer p, if p is not nil.
// b is returned, if p is nil.
func MustBool(p *bool, b bool) bool {
if p != nil {
return *p
}
return b
}
// Z2NBool returns a new pointer of given b bool.
// If b is zero value, it returns nil.
func Z2NBool(b bool) *bool {
if b == false {
return nil
}
return &b
}
// Int returns a new pointer of given i int.
func Int(i int) *int { return &i }
// MustInt returns a int value of pointer p, if p is not nil.
// i is returned, if p is nil.
func MustInt(p *int, i int) int {
if p != nil {
return *p
}
return i
}
// Z2NInt returns a new pointer of given i int.
// If i is zero value, it returns nil.
func Z2NInt(i int) *int {
if i == 0 {
return nil
}
return &i
}
// Int8 returns a new pointer of given i int8.
func Int8(i int8) *int8 { return &i }
// MustInt8 returns int value of pointer p, if p is not nil.
// i is returned, if p is nil.
func MustInt8(p *int8, i int8) int8 {
if p != nil {
return *p
}
return i
}
// Z2NInt8 returns a new pointer of given i int8.
// If i is zero value, it returns nil.
func Z2NInt8(i int8) *int8 {
if i == 0 {
return nil
}
return &i
}
// Int16 returns a new pointer of given i int16.
func Int16(i int16) *int16 { return &i }
// MustInt16 returns a int value of pointer p, if p is not nil.
// i is returned, if p is nil.
func MustInt16(p *int16, i int16) int16 {
if p != nil {
return *p
}
return i
}
// Z2NInt16 returns a new pointer of given i int16.
// If i is zero value, it returns nil.
func Z2NInt16(i int16) *int16 {
if i == 0 {
return nil
}
return &i
}
// Int32 returns a new pointer of given i int32.
func Int32(i int32) *int32 { return &i }
// MustInt32 returns a int value of pointer p, if p is not nil.
// i is returned, if p is nil.
func MustInt32(p *int32, i int32) int32 {
if p != nil {
return *p
}
return i
}
// Z2NInt32 returns a new pointer of given i int32.
// If i is zero value, it returns nil.
func Z2NInt32(i int32) *int32 {
if i == 0 {
return nil
}
return &i
}
// Int64 returns a new pointer of given i int64.
func Int64(i int64) *int64 { return &i }
// MustInt64 returns a int value of pointer p, if p is not nil.
// i is returned, if p is nil.
func MustInt64(p *int64, i int64) int64 {
if p != nil {
return *p
}
return i
}
// Z2NInt64 returns a new pointer of given i int64.
// If u is zero value, it returns nil.
func Z2NInt64(i int64) *int64 {
if i == 0 {
return nil
}
return &i
}
// Uint returns a new pointer of given u uint.
func Uint(u uint) *uint { return &u }
// MustUint returns a uint64 value of pointer p, if p is not nil.
// u is returned, if p is nil.
func MustUint(p *uint, u uint) uint {
if p != nil {
return *p
}
return u
}
// Z2NUint returns a new pointer of given u uint.
// If u is zero value, it returns nil.
func Z2NUint(u uint) *uint {
if u == 0 {
return nil
}
return &u
}
// Uint8 returns a new pointer of given u uint8.
func Uint8(u uint8) *uint8 { return &u }
// MustUint8 returns a uint8 value of pointer p, if p is not nil.
// u is returned, if p is nil.
func MustUint8(p *uint8, u uint8) uint8 {
if p != nil {
return *p
}
return u
}
// Z2NUint8 returns a new pointer of given u uint8.
// If u is zero value, it returns nil.
func Z2NUint8(u uint8) *uint8 {
if u == 0 {
return nil
}
return &u
}
// Uint16 returns a new pointer of given u uint16.
func Uint16(u uint16) *uint16 { return &u }
// MustUint16 returns a uint16 value of pointer p, if p is not nil.
// u is returned, if p is nil.
func MustUint16(p *uint16, u uint16) uint16 {
if p != nil {
return *p
}
return u
}
// Z2NUint16 returns a new pointer of given u uint16.
// If u is zero value, it returns nil.
func Z2NUint16(u uint16) *uint16 {
if u == 0 {
return nil
}
return &u
}
// Uint32 returns a new pointer of given u uint32.
func Uint32(u uint32) *uint32 { return &u }
// MustUint32 returns a uint32 value of pointer p, if p is not nil.
// u is returned, if p is nil.
func MustUint32(p *uint32, u uint32) uint32 {
if p != nil {
return *p
}
return u
}
// Z2NUint32 returns a new pointer of given u uint32.
// If u is zero value, it returns nil.
func Z2NUint32(u uint32) *uint32 {
if u == 0 {
return nil
}
return &u
}
// Uint64 returns a new pointer of given u uint64.
func Uint64(u uint64) *uint64 { return &u }
// MustUint64 returns a uint64 value of pointer p, if p is not nil.
// u is returned, if p is nil.
func MustUint64(p *uint64, u uint64) uint64 {
if p != nil {
return *p
}
return u
}
// Z2NUint64 returns a new pointer of given u uint64.
// If u is zero value, it returns nil.
func Z2NUint64(u uint64) *uint64 {
if u == 0 {
return nil
}
return &u
}
// Float32 returns a new pointer of given f float32.
func Float32(f float32) *float32 { return &f }
// MustFloat32 returns a float32 value of pointer p, if p is not nil.
// f is returned, if p is nil.
func MustFloat32(p *float32, f float32) float32 {
if p != nil {
return *p
}
return f
}
// Z2NFloat32 returns a new pointer of given f float32.
// If f is zero value, it returns nil.
func Z2NFloat32(f float32) *float32 {
if f == 0 {
return nil
}
return &f
}
// Float64 returns a new pointer of given i float64.
func Float64(f float64) *float64 { return &f }
// MustFloat64 returns a float64 value of pointer p, if p is not nil.
// f is returned, if p is nil.
func MustFloat64(p *float64, f float64) float64 {
if p != nil {
return *p
}
return f
}
// Z2NFloat64 returns a new pointer of given f float64.
// If f is zero value, it returns nil.
func Z2NFloat64(f float64) *float64 {
if f == 0 {
return nil
}
return &f
}
// Time returns a new pointer of given i time.Time.
func Time(t time.Time) *time.Time { return &t }
// MustTime returns a time.Time value of pointer p, if p is not nil.
// t is returned, if p is nil.
func MustTime(p *time.Time, t time.Time) time.Time {
if p != nil {
return *p
}
return t
}
// Z2NTime returns a new pointer of given t time.Time.
// If t is zero value, it returns nil.
func Z2NTime(t time.Time) *time.Time {
if t.IsZero() {
return nil
}
return &t
}