Is there a method to generate a UUID with go language

后端 未结 12 1716
温柔的废话
温柔的废话 2020-12-07 12:15

I have code that looks like this:

u := make([]byte, 16)
_, err := rand.Read(u)
if err != nil {
    return
}

u[8] = (u[8] | 0x80) & 0xBF // what does thi         


        
12条回答
  •  独厮守ぢ
    2020-12-07 12:24

    gofrs/uuid is the replacement for satori/go.uuid, which is the most starred UUID package for Go. It supports UUID versions 1-5 and is RFC 4122 and DCE 1.1 compliant.

    import "github.com/gofrs/uuid"
    
    // Create a Version 4 UUID, panicking on error
    u := uuid.Must(uuid.NewV4())
    

提交回复
热议问题