Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/jquiterio/uuid
- Owner: jquiterio
- License: mit
- Created: 2022-01-01T13:33:10.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-23T10:24:01.000Z (over 1 year ago)
- Last Synced: 2024-04-30T11:50:15.130Z (8 months ago)
- Topics: go, uuid, uuid-generator, uuid-parser, uuid-validator
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UUID - RFC4122
---
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 sliceu5 := 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"`
}
```