Commit 46b2215ebd14695c0d2bf23dc7a2157ffa2de7c0
1 parent
6b7121bdf6
Exists in
master
lintfix
Showing
4 changed files
with
20 additions
and
0 deletions
Show diff stats
default_values.go
... | ... | @@ -64,6 +64,7 @@ func Float64OrDefault(v *float64) float64 { |
64 | 64 | return 0.0 |
65 | 65 | } |
66 | 66 | |
67 | +// NilSafeInt32OrDefault ... | |
67 | 68 | func NilSafeInt32OrDefault(val *interface{}) int32 { |
68 | 69 | if *val != nil { |
69 | 70 | return (*val).(int32) |
... | ... | @@ -71,6 +72,7 @@ func NilSafeInt32OrDefault(val *interface{}) int32 { |
71 | 72 | return 0 |
72 | 73 | } |
73 | 74 | |
75 | +// NilSafeInt64OrDefault ... | |
74 | 76 | func NilSafeInt64OrDefault(val *interface{}) int64 { |
75 | 77 | if *val != nil { |
76 | 78 | return (*val).(int64) |
... | ... | @@ -78,6 +80,7 @@ func NilSafeInt64OrDefault(val *interface{}) int64 { |
78 | 80 | return 0 |
79 | 81 | } |
80 | 82 | |
83 | +// NilSafeUint32OrDefault ... | |
81 | 84 | func NilSafeUint32OrDefault(val *interface{}) uint32 { |
82 | 85 | if *val != nil { |
83 | 86 | return (*val).(uint32) |
... | ... | @@ -85,6 +88,7 @@ func NilSafeUint32OrDefault(val *interface{}) uint32 { |
85 | 88 | return 0 |
86 | 89 | } |
87 | 90 | |
91 | +// NilSafeUint64OrDefault ... | |
88 | 92 | func NilSafeUint64OrDefault(val *interface{}) uint64 { |
89 | 93 | if *val != nil { |
90 | 94 | return (*val).(uint64) |
... | ... | @@ -92,6 +96,7 @@ func NilSafeUint64OrDefault(val *interface{}) uint64 { |
92 | 96 | return 0 |
93 | 97 | } |
94 | 98 | |
99 | +// NilSafeFloat32OrDefault ... | |
95 | 100 | func NilSafeFloat32OrDefault(val *interface{}) float32 { |
96 | 101 | if *val != nil { |
97 | 102 | return (*val).(float32) |
... | ... | @@ -99,6 +104,7 @@ func NilSafeFloat32OrDefault(val *interface{}) float32 { |
99 | 104 | return 0.0 |
100 | 105 | } |
101 | 106 | |
107 | +// NilSafeFloat64OrDefault ... | |
102 | 108 | func NilSafeFloat64OrDefault(val *interface{}) float64 { |
103 | 109 | if *val != nil { |
104 | 110 | return (*val).(float64) |
... | ... | @@ -106,9 +112,11 @@ func NilSafeFloat64OrDefault(val *interface{}) float64 { |
106 | 112 | return 0.0 |
107 | 113 | } |
108 | 114 | |
115 | +// NilSafeStringOrDefault ... | |
109 | 116 | func NilSafeStringOrDefault(val *interface{}) string { |
110 | 117 | if *val != nil { |
111 | 118 | return (*val).(string) |
112 | 119 | } |
113 | 120 | return "" |
114 | 121 | } |
122 | + | ... | ... |
file_util.go
... | ... | @@ -8,6 +8,7 @@ import ( |
8 | 8 | "strings" |
9 | 9 | ) |
10 | 10 | |
11 | +// ReadFileContent ... | |
11 | 12 | func ReadFileContent(path string) ([]byte, error) { |
12 | 13 | f, err := os.Open(path) |
13 | 14 | if err != nil { |
... | ... | @@ -61,3 +62,4 @@ func InsertLine(lines *[]string, pos int64, l string) { |
61 | 62 | |
62 | 63 | *lines = append((*lines)[:pos], tail...) |
63 | 64 | } |
65 | + | ... | ... |
http.go
... | ... | @@ -58,14 +58,17 @@ func NotFoundHandlerFunc(w http.ResponseWriter, req *http.Request) { |
58 | 58 | NotFound(w, req, fmt.Sprintf("Resource you requested was not found: %s", req.URL.String())) |
59 | 59 | } |
60 | 60 | |
61 | +// SetContentType ... | |
61 | 62 | func SetContentType(w http.ResponseWriter, ctype string) { |
62 | 63 | w.Header().Set("Content-Type", ctype) |
63 | 64 | } |
64 | 65 | |
66 | +// SetResponseStatus ... | |
65 | 67 | func SetResponseStatus(w http.ResponseWriter, status int) { |
66 | 68 | w.WriteHeader(status) |
67 | 69 | } |
68 | 70 | |
71 | +// WriteResponse ... | |
69 | 72 | func WriteResponse(w http.ResponseWriter, content []byte) { |
70 | 73 | w.Write(content) |
71 | 74 | } |
... | ... | @@ -146,3 +149,4 @@ func Conflict(w http.ResponseWriter, r *http.Request, err string) { |
146 | 149 | func InternalServerError(w http.ResponseWriter, r *http.Request, err string) { |
147 | 150 | Error(w, r, http.StatusInternalServerError, err) |
148 | 151 | } |
152 | + | ... | ... |
string_util.go
... | ... | @@ -70,15 +70,18 @@ func ReplaceAny(s, patern, r string) (n string) { |
70 | 70 | return n |
71 | 71 | } |
72 | 72 | |
73 | +// StringToBool ... | |
73 | 74 | func StringToBool(s string) bool { |
74 | 75 | res, _ := strconv.ParseBool(s) |
75 | 76 | return res |
76 | 77 | } |
77 | 78 | |
79 | +// BoolToString ... | |
78 | 80 | func BoolToString(b bool) string { |
79 | 81 | return fmt.Sprintf("%b", b) |
80 | 82 | } |
81 | 83 | |
84 | +// StringSliceContains ... | |
82 | 85 | func StringSliceContains(slice []string, s string) bool { |
83 | 86 | for i := range slice { |
84 | 87 | if slice[i] == s { |
... | ... | @@ -88,6 +91,7 @@ func StringSliceContains(slice []string, s string) bool { |
88 | 91 | return false |
89 | 92 | } |
90 | 93 | |
94 | +// StringAt ... | |
91 | 95 | func StringAt(s string, index int) string { |
92 | 96 | if len(s)-1 < index || index < 0 { |
93 | 97 | return "" |
... | ... | @@ -96,6 +100,7 @@ func StringAt(s string, index int) string { |
96 | 100 | return string(s[index]) |
97 | 101 | } |
98 | 102 | |
103 | +// SplitStringAtWholeWords ... | |
99 | 104 | func SplitStringAtWholeWords(s string, maxLen int) (res []string) { |
100 | 105 | parts := strings.Split(s, " ") |
101 | 106 | |
... | ... | @@ -118,3 +123,4 @@ func SplitStringAtWholeWords(s string, maxLen int) (res []string) { |
118 | 123 | |
119 | 124 | return res |
120 | 125 | } |
126 | + | ... | ... |