Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shibukawa/uuid62
Short ID generator by using UUIDv4 and base62
https://github.com/shibukawa/uuid62
tw
Last synced: about 1 month ago
JSON representation
Short ID generator by using UUIDv4 and base62
- Host: GitHub
- URL: https://github.com/shibukawa/uuid62
- Owner: shibukawa
- License: apache-2.0
- Created: 2019-06-28T11:59:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-31T23:28:49.000Z (over 1 year ago)
- Last Synced: 2024-06-19T11:19:30.714Z (6 months ago)
- Topics: tw
- Language: Go
- Size: 11.7 KB
- Stars: 19
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# uuid62
[![GoDoc](http://godoc.org/github.com/shibukawa/uuid62/v2?status.svg)](http://godoc.org/github.com/shibukawa/uuid62/v2)
Go implementation of short ID generator by using UUIDv1, V4, V6, V7 and base62 inspired by [npm uuid62 package](https://www.npmjs.com/package/uuid62).
It always return strings whose length is 21 or 22. It is shorter than string represention of UUID (36).
And the results includes only alphabet and numeric characters (no symbols).```go
package mainimport (
"fmt"
"github.com/shibukawa/uuid62/v2"
)func main() {
// it just returns string
idString, err := uuid62.V1()
if err != nil {
fmt.Println(idString)
}// it also provides API decode/encode between UUID
uuid, err := Decode(idString)
if err != nil {
fmt.Println(idString)
}
idStringAgain := Encode(uuid) // idStringAgain == idString
fmt.Println(idStringAgain)
}
```## API
### Generator Functions
- `func uuid62.V1() (string, error)`
- `func uuid62.V4() (string, error)`
- `func uuid62.V6() (string, error)`
- `func uuid62.V7() (string, error)`They generates UUID string in base62 format.
### Helper Functions
- `func uuid62.Decode(uuidString string) (uuid.UUID, error)`
Convert string to `github.com/gofrs/uuid`'s UUID object.
- `func uuid62.Encode(uuid.UUID uuidObj) (string, error)`
Convert `github.com/gofrs/uuid`'s UUID object to string.
- `func uuid62.Timestamp(uuidString string) (time.Time, error)`
Get timestamp from uuid string. It accepts only V1 and V6.
## Change History
### v1 -> v2
``uuid62.V7Nano`` and ``uuid62.V7Micro`` and ``uuid62.V7Milli`` and removed and introduced ``uuid62.V7`` because the latest uuid draft removes precision option from V7.
Change base62 encode character order. Now resulting strings have also same order with original UUID. So the resulting string is also k-sortable.
## License
Apache 2