Another UUID generator and parser for Go. Returns UUID or Nil
go get -u github.com/jquiterio/uuid
func main(){
// new V4
u := uuid.New() // or u := uuid.NewV4() generates a new UUID v4.
u.String() // returns a string uuid
u.Bytes() // retruns a byte slice
u5 := uuid.NewV5() // generates a new UUID v5
u5.String()
u5.Bytes() // retruns a byte slice
// Parse UUID
// Get UUID from String
ufs := uuid.Parse("c5302009-7ff6-47d2-9a1c-72601da3e3e5")
ufs.String()
// Get UUID from Bytes
ufb := Parse(uuid.New().Bytes())
// IsValid: Check if UUID is Valid
uuid.IsValid("something") // may return false
uuid.IsValid("c5302009-7ff6-47d2-9a1c-72601da3e3e5") // take ufmay return true
}
Go struct with GORM
type User struct {
UUID uuid.UUID `gorm:"type:uuid" json:"uuid"`
Name string `json:"name"`
}