-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams.helpers.go
112 lines (106 loc) · 2.25 KB
/
params.helpers.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
package dyanmic_params
import "time"
// Use any function started with Q as a faster way of calling
// methods. It suppress any error and returns the zero-value
// of the associated type. So, if errors are very important,
// do not use Q* methods and go with original methods without
// Q at the beginning of their name.
func QNewDynamicParams(vars ...interface{}) *DynamicParams {
source := SrcNameInternal
var ok bool
if len(vars) != 0 {
source, ok = vars[0].(string)
if !ok {
panic("cannot accepts a parameter which is not a string, as the source name")
}
}
if len(vars) > 1 {
return NewDynamicParams(source, vars[1:]...)
} else {
return NewDynamicParams(source)
}
}
func (d *DynamicParams) QGetString(key string) string {
v, err := d.GetAsString(key)
if err != nil {
return ""
}
return v
}
func (d *DynamicParams) QGetInt(key string) int {
v, err := d.GetAsInt(key)
if err != nil {
return 0
}
return v
}
func (d *DynamicParams) QGetInt64(key string) int64 {
v, err := d.GetAsInt64(key)
if err != nil {
return 0
}
return v
}
func (d *DynamicParams) QGetInt32(key string) int32 {
v, err := d.GetAsInt32(key)
if err != nil {
return 0
}
return v
}
func (d *DynamicParams) QGetInt8(key string) int8 {
v, err := d.GetAsInt8(key)
if err != nil {
return 0
}
return v
}
func (d *DynamicParams) QGetBool(key string) bool {
v, err := d.GetAsBool(key)
if err != nil {
return false
}
return v
}
func (d *DynamicParams) QGetQuotedString(key string) string {
v, err := d.GetAsQuotedString(key)
if err != nil {
return ""
}
return v
}
func (d *DynamicParams) QGetBytes(key string) []byte {
v, err := d.GetAsBytes(key)
if err != nil {
return nil
}
return v
}
func (d *DynamicParams) QGetStringAsBool(key string) bool {
v, err := d.GetStringAsBool(key)
if err != nil {
return false
}
return v
}
func (d *DynamicParams) QGetStringAsInt(key string) int {
v, err := d.GetStringAsInt(key)
if err != nil {
return 0
}
return v
}
func (d *DynamicParams) QGetTimeDuration(key string) *time.Duration {
v, err := d.GetAsTimeDuration(key)
if err != nil {
return nil
}
return v
}
func (d *DynamicParams) QGetStringAsTimeDuration(key string) *time.Duration {
v, err := d.GetStringAsTimeDuration(key)
if err != nil {
return nil
}
return v
}