You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gostring/uuid.go

19 lines
446 B

package gostring
import (
"crypto/rand"
"fmt"
"time"
)
// GetUuId 由 32 个十六进制数字组成,以 6 个组显示,由连字符 - 分隔
func GetUuId() string {
unix32bits := uint32(time.Now().UTC().Unix())
buff := make([]byte, 12)
numRead, err := rand.Read(buff)
if numRead != len(buff) || err != nil {
return ""
}
return fmt.Sprintf("%x-%x-%x-%x-%x-%x", unix32bits, buff[0:2], buff[2:4], buff[4:6], buff[6:8], buff[8:])
}