https://github.com/yankeguo-deprecated/snowflake-alt
A concurrent-safe lock-free implementation of snowflake algorithm in Golang
https://github.com/yankeguo-deprecated/snowflake-alt
algorithm golang id-generator snowflake
Last synced: 8 months ago
JSON representation
A concurrent-safe lock-free implementation of snowflake algorithm in Golang
- Host: GitHub
- URL: https://github.com/yankeguo-deprecated/snowflake-alt
- Owner: yankeguo-deprecated
- License: mit
- Created: 2020-01-02T16:58:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-30T14:30:14.000Z (over 4 years ago)
- Last Synced: 2025-02-14T16:59:01.119Z (10 months ago)
- Topics: algorithm, golang, id-generator, snowflake
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# snowflake
A concurrent-safe lock-free implementation of snowflake algorithm in Golang
## Get
`go get -u go.guoyk.net/snowflake`
## Usage
```go
// assign a unique identifier
id, _ := strconv.ParseUint(os.Getenv("WORKER_ID"), 10, 64)
// create a instance
s := snowflake.New(snowflake.Options{
Epoch: time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC),
ID: id,
})
// get a id
s.NewID()
// stop and release all related resource
s.Stop()
```
## Performance
Less than `1us/op`
## Credits
Guo Y.K., MIT License