Skip to content

jquiterio/uuid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UUID - RFC4122

Build Status Code Coverage Go Report Card Release Version GoDoc License


Another UUID generator and parser for Go. Returns UUID or Nil

Usage

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"`
}

Releases

No releases published

Packages

No packages published

Languages