diff --git a/default_values.go b/default_values.go index 396bf70..2d34c64 100644 --- a/default_values.go +++ b/default_values.go @@ -64,6 +64,7 @@ func Float64OrDefault(v *float64) float64 { return 0.0 } +// NilSafeInt32OrDefault ... func NilSafeInt32OrDefault(val *interface{}) int32 { if *val != nil { return (*val).(int32) @@ -71,6 +72,7 @@ func NilSafeInt32OrDefault(val *interface{}) int32 { return 0 } +// NilSafeInt64OrDefault ... func NilSafeInt64OrDefault(val *interface{}) int64 { if *val != nil { return (*val).(int64) @@ -78,6 +80,7 @@ func NilSafeInt64OrDefault(val *interface{}) int64 { return 0 } +// NilSafeUint32OrDefault ... func NilSafeUint32OrDefault(val *interface{}) uint32 { if *val != nil { return (*val).(uint32) @@ -85,6 +88,7 @@ func NilSafeUint32OrDefault(val *interface{}) uint32 { return 0 } +// NilSafeUint64OrDefault ... func NilSafeUint64OrDefault(val *interface{}) uint64 { if *val != nil { return (*val).(uint64) @@ -92,6 +96,7 @@ func NilSafeUint64OrDefault(val *interface{}) uint64 { return 0 } +// NilSafeFloat32OrDefault ... func NilSafeFloat32OrDefault(val *interface{}) float32 { if *val != nil { return (*val).(float32) @@ -99,6 +104,7 @@ func NilSafeFloat32OrDefault(val *interface{}) float32 { return 0.0 } +// NilSafeFloat64OrDefault ... func NilSafeFloat64OrDefault(val *interface{}) float64 { if *val != nil { return (*val).(float64) @@ -106,9 +112,11 @@ func NilSafeFloat64OrDefault(val *interface{}) float64 { return 0.0 } +// NilSafeStringOrDefault ... func NilSafeStringOrDefault(val *interface{}) string { if *val != nil { return (*val).(string) } return "" } + diff --git a/file_util.go b/file_util.go index 98c24b5..6423148 100644 --- a/file_util.go +++ b/file_util.go @@ -8,6 +8,7 @@ import ( "strings" ) +// ReadFileContent ... func ReadFileContent(path string) ([]byte, error) { f, err := os.Open(path) if err != nil { @@ -61,3 +62,4 @@ func InsertLine(lines *[]string, pos int64, l string) { *lines = append((*lines)[:pos], tail...) } + diff --git a/http.go b/http.go index 2435465..d14825f 100644 --- a/http.go +++ b/http.go @@ -58,14 +58,17 @@ func NotFoundHandlerFunc(w http.ResponseWriter, req *http.Request) { NotFound(w, req, fmt.Sprintf("Resource you requested was not found: %s", req.URL.String())) } +// SetContentType ... func SetContentType(w http.ResponseWriter, ctype string) { w.Header().Set("Content-Type", ctype) } +// SetResponseStatus ... func SetResponseStatus(w http.ResponseWriter, status int) { w.WriteHeader(status) } +// WriteResponse ... func WriteResponse(w http.ResponseWriter, content []byte) { w.Write(content) } @@ -146,3 +149,4 @@ func Conflict(w http.ResponseWriter, r *http.Request, err string) { func InternalServerError(w http.ResponseWriter, r *http.Request, err string) { Error(w, r, http.StatusInternalServerError, err) } + diff --git a/string_util.go b/string_util.go index e91f655..640f7e1 100644 --- a/string_util.go +++ b/string_util.go @@ -70,15 +70,18 @@ func ReplaceAny(s, patern, r string) (n string) { return n } +// StringToBool ... func StringToBool(s string) bool { res, _ := strconv.ParseBool(s) return res } +// BoolToString ... func BoolToString(b bool) string { return fmt.Sprintf("%b", b) } +// StringSliceContains ... func StringSliceContains(slice []string, s string) bool { for i := range slice { if slice[i] == s { @@ -88,6 +91,7 @@ func StringSliceContains(slice []string, s string) bool { return false } +// StringAt ... func StringAt(s string, index int) string { if len(s)-1 < index || index < 0 { return "" @@ -96,6 +100,7 @@ func StringAt(s string, index int) string { return string(s[index]) } +// SplitStringAtWholeWords ... func SplitStringAtWholeWords(s string, maxLen int) (res []string) { parts := strings.Split(s, " ") @@ -118,3 +123,4 @@ func SplitStringAtWholeWords(s string, maxLen int) (res []string) { return res } +