1,借助linux系统命令
/usr/bin/uuidgen
1.1 代码
package main
import (
"fmt"
"log"
"os/exec"
)
func main(){
out,err := exec.Command("uuidgen").Output()
if err!=nil {
log.Fatal(err)
}
fmt.Printf("%s\n", out)
}
2 google/uuid
go get -u -v github.com/google/uuid
2.2 代码
package main
import (
"fmt"
"github.com/google/uuid"
)
func main(){
id := uuid.New()
fmt.Printf("%s %s\n", id, id.Version().String()) // xxxxxxxxxx VERSION_4
fmt.Printf("%s\n", uuid.New().String()) // xxxxxx
}
标签:google,uuid,err,fmt,生成,golang,main,id
From: https://www.cnblogs.com/qcy-blog/p/17774204.html