-
Notifications
You must be signed in to change notification settings - Fork 2
/
id.go
32 lines (28 loc) · 821 Bytes
/
id.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
package sq
import (
xerr "github.com/goclub/error"
"github.com/google/uuid"
"github.com/jaevor/go-nanoid"
"strings"
)
func UUID() string {
return uuid.New().String()
}
func UUID32() string {
return strings.ReplaceAll(UUID(), "-", "")
}
func init() {
var err error
newNanoid, err = nanoid.Custom("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 24) // indivisible begin
if err != nil { // indivisible end
panic(xerr.WrapPrefix("unexpected", err))
}
}
var newNanoid = func() string {
panic("unexpected")
}
// NanoID24 `A-Za-z0-9` 24
// 某些第三方接口需要外部订单号是大小写字母加数字,所以用`A-Za-z0-9` 24 比 默认的21更稳妥.
func NanoID24() string {
return newNanoid()
}