-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.go
51 lines (46 loc) · 852 Bytes
/
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
package main
import (
"bytes"
"fmt"
"math/rand"
"time"
)
func ParseInterface(arg *interface{}) string {
var result string
switch v := (*arg).(type) {
case nil:
result = "NULL"
break
case bool:
if v {
result = "1"
} else {
result = "0"
}
break
case []byte:
result = fmt.Sprintf("%v", string(v))
break
case time.Time:
result = fmt.Sprintf("%v", v.Format("2006-01-02 15:04:05.999"))
break
case bytes.Buffer:
result = fmt.Sprintf("%v", v)
break
default:
result = fmt.Sprintf("%+v", v)
}
return result
}
func ParseValue(args ...*interface{}) string {
a := args[0]
return ParseInterface(a)
}
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}