/
only_v3.go
53 lines (46 loc) · 856 Bytes
/
only_v3.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
package utls
import (
"crypto/md5"
"crypto/rand"
"encoding/base64"
"encoding/hex"
"strconv"
"strings"
)
//create 32bit md5 string
func GetMd5String(s string, upper bool, half bool) string {
h := md5.New()
h.Write([]byte(s))
result := hex.EncodeToString(h.Sum(nil))
if upper == true {
result = strings.ToUpper(result)
}
if half == true {
result = result[8:24]
}
return result
}
//use rand number create Guid string
func NewOnly_v3() string {
b := make([]byte, 48)
if _, err := rand.Read(b); err != nil {
return ""
}
return GetMd5String(base64.URLEncoding.EncodeToString(b), true, false)
}
func NewInt64_v3() (id int64) {
sid := NewOnly_v3()
if len(sid) == 0 {
return
}
val, err := strconv.Atoi(sid)
if err != nil {
panic(err)
return
}
id = int64(val)
return
}
func NewString_v3() string {
return NewOnly_v3()
}