/
util.go
54 lines (49 loc) · 882 Bytes
/
util.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
package builtin
import (
"fmt"
"strconv"
. "github.com/infrago/base"
"github.com/infrago/infra"
"github.com/infrago/util"
)
// 密码加密格式
func password(str string) string {
return util.Sha1(str)
}
func anyToString(val Any) string {
sv := ""
switch v := val.(type) {
case string:
sv = v
case int:
sv = strconv.Itoa(v)
case int64:
sv = strconv.FormatInt(v, 10)
case bool:
sv = strconv.FormatBool(v)
case Map:
d, e := infra.MarshalJSON(v)
if e == nil {
sv = string(d)
} else {
sv = "{}"
}
case []Map:
d, e := infra.MarshalJSON(v)
if e == nil {
sv = string(d)
} else {
sv = "[]"
}
case []int, []int8, []int16, []int32, []int64, []float32, []float64, []string, []bool, []Any:
d, e := infra.MarshalJSON(v)
if e == nil {
sv = string(d)
} else {
sv = "[]"
}
default:
sv = fmt.Sprintf("%v", v)
}
return sv
}