mirror of
https://github.com/godruoyi/go-snowflake.git
synced 2026-01-03 19:03:57 +00:00
Compare commits
5 Commits
v0.0.1-bet
...
v0.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0500e4b57b | ||
|
|
937cb414e9 | ||
|
|
495d927cce | ||
|
|
03bb06070a | ||
|
|
20079db81e |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Godruoyi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -2,13 +2,18 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/godruoyi/go-snowflake"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// set starttime and machineID for the first time if you wan't to use the default value
|
||||
snowflake.SetStartTime(time.Date(2021, 9, 1, 0, 0, 0, 0, time.UTC))
|
||||
snowflake.SetMachineID(snowflake.PrivateIPToMachineID()) // testing, not to be used in production
|
||||
|
||||
id := snowflake.ID()
|
||||
fmt.Println(id)
|
||||
fmt.Println(id) // 1537200202186752
|
||||
|
||||
sid := snowflake.ParseID(id)
|
||||
// SID {
|
||||
|
||||
@@ -36,7 +36,7 @@ So if you want use the snowflake algorithm to generate unique ID, You must ensur
|
||||
|
||||
Based on this, we created this package and integrated multiple sequence-number providers into it.
|
||||
|
||||
* AtomicResolver (base sync/atmoic)
|
||||
* AtomicResolver (base sync/atomic)
|
||||
|
||||
> Each provider only needs to ensure that the serial number generated in the same millisecond is different. You can get a unique ID.
|
||||
|
||||
@@ -54,7 +54,7 @@ Based on this, we created this package and integrated multiple sequence-number p
|
||||
$ go get github.com/godruoyi/go-snowflake
|
||||
```
|
||||
|
||||
## Useage
|
||||
## Usage
|
||||
|
||||
1. simple to use.
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ func SetStartTime(s time.Time) {
|
||||
panic("The start time cannot be a zero value")
|
||||
}
|
||||
|
||||
if s.After(time.Now()) {
|
||||
if s.After(time.Now().UTC()) {
|
||||
panic("The s cannot be greater than the current millisecond")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user