-
Notifications
You must be signed in to change notification settings - Fork 0
/
com.go
56 lines (48 loc) · 1014 Bytes
/
com.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
package skt
import (
"crypto/md5"
"encoding/hex"
"fmt"
"os"
"reflect"
"runtime"
"strconv"
)
// IsExist whether a file or directory exists
func IsExist(name string) bool {
_, err := os.Stat(name)
if err != nil && os.IsNotExist(err) {
return false
}
return true
}
// IsWindows whether Windows system
func IsWindows() bool {
if runtime.GOOS == "windows" {
return true
}
return false
}
// IsBlank whether blank
func IsBlank(value reflect.Value) bool {
return reflect.DeepEqual(value.Interface(), reflect.Zero(value.Type()).Interface())
}
// MD5 crypto
func MD5(s string) string {
h := md5.New()
h.Write([]byte(s))
return hex.EncodeToString(h.Sum(nil))
}
// ToString 转换任意值为string
func ToString(i interface{}) string {
return fmt.Sprint(i)
}
// ToByte 转换任意值为[]byte
func ToByte(i interface{}) []byte {
return []byte(fmt.Sprint(i))
}
// ToInt64 转换任意值为int64
func ToInt64(i interface{}) int64 {
num, _ := strconv.Atoi(fmt.Sprint(i))
return int64(num)
}