diff --git a/format_utility.go b/format_utility.go new file mode 100644 index 0000000..4d45a6a --- /dev/null +++ b/format_utility.go @@ -0,0 +1,57 @@ +package main + +import ( + "strings" + "time" + "strconv" +) + +//// +//// TIME FORMAT UTILITY +//// + +func unixToDate(input int64) time.Time { + return time.Unix(input, 0) +} + +func dateToUnix(input interface{}) int64 { + if input != nil { + t := input.(time.Time) + return t.Unix() + + } + return 0 +} + +func aersDate(unixString string) (string, error) { + unixTime, err := strconv.ParseInt(unixString, 10, 64) + if err != nil { + return "", err + } + + date := unixToDate(unixTime).String() + tokens := strings.Split(date, "-") + dateString := tokens[0] + tokens[1] + strings.Split(tokens[2], " ")[0] + + return dateString, nil +} + +//// +//// STRING UTILITY +//// + +// surrondWithSingleQuotes is used when url param is of type string +func putQuotes(input string) string { + if input != "" { + return " = '" + input + "'" + } + return "" +} + +func putLikeQuotes(input string) string { + if input != "" { + return " LIKE UPPER('%" + input + "%')" + } + return "" +} + diff --git a/json_utility.go b/json_utility.go index ebf008c..81fa7eb 100644 --- a/json_utility.go +++ b/json_utility.go @@ -5,6 +5,8 @@ import ( "strings" ) +const APIVersion "/api/v1" + type LangMap map[string]map[string]string type Field struct { @@ -66,5 +68,3 @@ func NewJSONPayload(r *http.Request, params JSONParams) JSONPayload { return obj } -func decodeRequestBody(req *http.Request, model interface{}) {} -