uuid
最后更新于:2022-04-02 02:40:46
[TOC]
> [参考](https://github.com/gofrs/uuid)
## 安装
`go get github.com/gofrs/uuid`
## 使用
```
package main
import (
"log"
"github.com/gofrs/uuid"
)
var u1 = uuid.Must(uuid.NewV4())
func main() {
// Create a Version 4 UUID.
u2, err := uuid.NewV4()
if err != nil {
log.Fatalf("failed to generate UUID: %v", err)
}
log.Printf("generated Version 4 UUID %v", u2)
// Parse a UUID from a string.
s := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
u3, err := uuid.FromString(s)
if err != nil {
log.Fatalf("failed to parse UUID %q: %v", s, err)
}
log.Printf("successfully parsed UUID %v", u3)
}
```
';