赞
踩
推荐包
https://github.com/satori/go.uuid
安装
go get github.com/satori/go.uuid
示例代码
package mainimport ("fmt""github.com/satori/go.uuid")func main() {// 创建UUID版本4// 对错误报错u1 := uuid.Must(uuid.NewV4())fmt.Printf("UUIDv4: %s", u1)// 或者错误处理u2, err := uuid.NewV4()if err != nil {fmt.Printf("Something went wrong: %s", err)return}fmt.Printf("UUIDv4: %s", u2)// 从字符串输入解析UUIDu2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")if err != nil {fmt.Printf("Something went wrong: %s", err)return}fmt.Printf("Successfully parsed: %s", u2)}
生成唯一uuid并转为字符串
uuid4 := uuid.Must(uuid.NewV4(), nil).String()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。