Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jquiterio/uuid

UUID golang
https://github.com/jquiterio/uuid

go uuid uuid-generator uuid-parser uuid-validator

Last synced: about 1 month ago
JSON representation

UUID golang

Awesome Lists containing this project

README

        

# 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`

```go
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

```go
type User struct {
UUID uuid.UUID `gorm:"type:uuid" json:"uuid"`
Name string `json:"name"`
}
```