2024-02-11 01:31:01 +08:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/jaevor/go-nanoid"
|
2024-06-14 17:23:24 +08:00
|
|
|
ulid "github.com/oklog/ulid/v2"
|
2024-02-11 01:31:01 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func NanoID() string {
|
|
|
|
nanoid, _ := nanoid.CustomASCII("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 21)
|
|
|
|
return nanoid()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NanoIDInt() (id int64, err error) {
|
2024-04-19 16:35:27 +08:00
|
|
|
decenaryID, err := nanoid.CustomASCII("0123456789", 18)
|
2024-02-11 01:31:01 +08:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
id, err = strconv.ParseInt(decenaryID(), 10, 64)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func UUID() string {
|
|
|
|
return uuid.NewString()
|
|
|
|
}
|
2024-06-14 17:23:24 +08:00
|
|
|
|
|
|
|
func ULID() string {
|
|
|
|
return ulid.Make().String()
|
|
|
|
}
|