这也是个uuid库,不过看好多开源项目用这个包,也记录下吧
项目地址:https://github.com/google/uuid
type UUID
type UUID [16]byte
func FromBytes(b []byte) (uuid UUID, err error) 转换
func Must(uuid UUID, err error) UUID 判断必须是uuid
func Parse(s string) (UUID, error) 将字符串转为uuid
func ParseBytes(b []byte) (UUID, error)
func MustParse(s string) UUID MustParse与Parse类似,但如果字符串不能被解析,则为panic
func New() UUID v1
func NewDCEGroup() (UUID, error) v2
func NewDCEPerson() (UUID, error) v2
func NewDCESecurity(domain Domain, id uint32) (UUID, error) v2
func NewMD5(space UUID, data []byte) UUID v3
func NewRandom() (UUID, error) v4
func NewSHA1(space UUID, data []byte) UUID v5
func (uuid UUID) ClockSequence() int 返回时钟序列
func (uuid UUID) Domain() Domain 返回域
func (uuid UUID) ID() uint32 ID返回版本2 UUID的ID
func (uuid UUID) NodeID() []byte NodeID返回以uuid编码的6字节节点id
func (uuid UUID) String() string uuid的string形式
func (uuid UUID) Time() Time uuid编码的自15oct 1582以来的时间,以100纳秒为单位。对v1 v2有效
import (
"fmt"
"github.com/google/uuid"
)
func main() {
for i := 0; i < 10; i++ {
uid := uuid.New()
fmt.Println(uid.ID())
fmt.Println(uid.String())
}
}