-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.go
executable file
·99 lines (87 loc) · 1.52 KB
/
tools.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package utils
import (
"io"
"mime/multipart"
"os"
"regexp"
)
// 校验手机号
func VerifyMobileFormat(mobileNum string) bool {
regular := "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$"
reg := regexp.MustCompile(regular)
return reg.MatchString(mobileNum)
}
//bool转[]bytez
func BoolIntoByte(b bool) []byte {
if b {
return []byte{1}
} else {
return []byte{0}
}
}
//byte转bool
func ByteIntoBool(b []byte) bool {
if b[0] == 1 {
return true
} else {
return false
}
}
//byte转int
func ByteIntoInt(b []byte) uint8 {
if b[0] == 1 {
return 1
} else {
return 0
}
}
//bool转int
func BoolIntoInt(b bool) int {
if b {
return 1
} else {
return 0
}
}
//用于转化前端字符串布尔值为[]byte
func StrBoolIntoByte(s string) []byte {
if s == "true" {
return []byte{1}
} else {
return []byte{0}
}
}
//用于转化前端字符串布尔值为[]byte
func StrGenderIntoByte(s string) []byte {
if s == "男" {
return []byte{1}
} else {
return []byte{0}
}
}
// 启用未启用状态布尔转字符串
func ByteEnabledToString(b []byte) string {
if b[0] == 0 {
return `禁用`
} else {
return `启用`
}
}
func SaveFile(file *multipart.FileHeader, dst string) error {
err := os.MkdirAll("./static/uploadfile/", os.ModePerm)
if err != nil {
return err
}
src, err := file.Open()
if err != nil {
return err
}
defer src.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, src)
return err
}