Commit 514fa9dd680613dec6bd8f07001f106c23c9a042

Authored by Marko Tikvić
1 parent 64041a2ea4
Exists in master and in 1 other branch v2

added formating utility

Showing 2 changed files with 59 additions and 2 deletions   Show diff stats
format_utility.go
... ... @@ -0,0 +1,57 @@
  1 +package main
  2 +
  3 +import (
  4 + "strings"
  5 + "time"
  6 + "strconv"
  7 +)
  8 +
  9 +////
  10 +//// TIME FORMAT UTILITY
  11 +////
  12 +
  13 +func unixToDate(input int64) time.Time {
  14 + return time.Unix(input, 0)
  15 +}
  16 +
  17 +func dateToUnix(input interface{}) int64 {
  18 + if input != nil {
  19 + t := input.(time.Time)
  20 + return t.Unix()
  21 +
  22 + }
  23 + return 0
  24 +}
  25 +
  26 +func aersDate(unixString string) (string, error) {
  27 + unixTime, err := strconv.ParseInt(unixString, 10, 64)
  28 + if err != nil {
  29 + return "", err
  30 + }
  31 +
  32 + date := unixToDate(unixTime).String()
  33 + tokens := strings.Split(date, "-")
  34 + dateString := tokens[0] + tokens[1] + strings.Split(tokens[2], " ")[0]
  35 +
  36 + return dateString, nil
  37 +}
  38 +
  39 +////
  40 +//// STRING UTILITY
  41 +////
  42 +
  43 +// surrondWithSingleQuotes is used when url param is of type string
  44 +func putQuotes(input string) string {
  45 + if input != "" {
  46 + return " = '" + input + "'"
  47 + }
  48 + return ""
  49 +}
  50 +
  51 +func putLikeQuotes(input string) string {
  52 + if input != "" {
  53 + return " LIKE UPPER('%" + input + "%')"
  54 + }
  55 + return ""
  56 +}
  57 +
... ...
... ... @@ -5,6 +5,8 @@ import (
5 5 "strings"
6 6 )
7 7  
  8 +const APIVersion "/api/v1"
  9 +
8 10 type LangMap map[string]map[string]string
9 11  
10 12 type Field struct {
... ... @@ -66,5 +68,3 @@ func NewJSONPayload(r *http.Request, params JSONParams) JSONPayload {
66 68 return obj
67 69 }
68 70  
69   -func decodeRequestBody(req *http.Request, model interface{}) {}
70   -
... ...