赞
踩
一般会有获取uuid的需求用于做客户端检测之类的,这里找到一个包,简单做下总结:
github.com/satori/go.uuid
package main import ( "fmt" "github.com/satori/go.uuid" ) func main() { // Creating UUID Version 4 // panic on error u1 := uuid.Must(uuid.NewV4()) fmt.Printf("UUIDv4: %s\n", u1) // or error handling u2, err := uuid.NewV4() if err != nil { fmt.Printf("Something went wrong: %s", err) return } fmt.Printf("UUIDv4: %s\n", u2) // Parsing UUID from string input u2, 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) }
可能报如下错误:
assignment mismatch: 2 variables but uuid.NewV4 returns 1 values
在issue上找到答案:
即:
go get -u github.com/satori/go.uuid@master
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。