-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
76 lines (50 loc) · 1018 Bytes
/
utils.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package msgraph
import (
"database/sql"
"encoding/json"
"strconv"
"strings"
"time"
)
func NotIn(value interface{}, list ...interface{}) bool {
for _, element := range list {
if value == element {
return false
}
}
return true
}
func AnyToString(value any) (str string) {
switch v := value.(type) {
case int:
str = strconv.Itoa(v)
case int32:
str = strconv.FormatInt(int64(v), 10)
case int8, int16, int64:
str = strconv.FormatInt(v.(int64), 10)
case float32, float64:
str = strconv.FormatFloat(v.(float64), byte('f'), -1, 64)
case bool:
str = strconv.FormatBool(v)
case []string:
str = strings.Join(v, ",")
case string, []byte:
str = v.(string)
case sql.NullString:
str = v.String
case time.Time:
str = v.Format(time.RFC3339)
case nil:
str = ""
default:
str, _ = ToJson(v)
}
return
}
func ToJson(data interface{}) (jsn string, err error) {
var bytes []byte
if bytes, err = json.Marshal(data); err == nil {
jsn = string(bytes)
}
return
}