-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
41 lines (36 loc) · 675 Bytes
/
Copy pathutils.go
File metadata and controls
41 lines (36 loc) · 675 Bytes
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
package main
import (
"encoding/json"
"strconv"
)
// ToJSON util
func ToJSON(v interface{}, indents ...bool) string {
var dt []byte
if len(indents) > 0 && indents[0] {
dt, _ = json.MarshalIndent(v, "", " ")
} else {
dt, _ = json.Marshal(v)
}
return string(dt)
}
// ToStr util
func ToStr(i interface{}) string {
if i == nil {
return ""
}
switch i.(type) {
case string:
return i.(string)
case int:
return strconv.Itoa(i.(int))
case int8:
return strconv.Itoa(int(i.(int8)))
case int16:
return strconv.Itoa(int(i.(int16)))
case int32:
return strconv.Itoa(int(i.(int32)))
case int64:
return strconv.FormatInt(i.(int64), 10)
}
return ""
}