Skip to main content

uuid

uuid 在实际开发中普遍使用,下面列举的是uuid的3种生成方式

1, https://github.com/satori/go.uuid 4k star

package main

import (
"fmt"

"github.com/satori/go.uuid"
"log"
)

func main() {
log.Println(fmt.Sprintf("%s",uuid.NewV4()))
}

2, consul用的uuid库 https://github.com/hashicorp/go-uuid 139 star consul用的uuid库:https://github.com/hashicorp/go-uuid 12.4k users, 出自 https://www.consul.io/api-docs

package main

import (
"fmt"
"github.com/hashicorp/go-uuid"
)

func main() {
id, err:=uuid.GenerateUUID()
if err!=nil{
panic(err)
}
fmt.Println(id)
}

  1. google的uuid https://github.com/google/uuid 3k star
#install
go get github.com/google/uuid