Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrOverTimestampLimit over the timestamp limit error. ErrOverTimestampLimit = errors.New("over the timestamp limit") // ErrClockBackward clock backward error. ErrClockBackward = errors.New("the clock backward") // ErrInvalidStartTime invalid start time error. ErrInvalidStartTime = errors.New("invalid start time") // ErrInvalidLastGenerateTime invalid last generate time error. ErrInvalidLastGenerateTime = errors.New("invalid last generate time") // ErrInvalidMaxTolerateMillis invalid max tolerate millis error. ErrInvalidMaxTolerateMillis = errors.New("invalid max tolerate millis") // ErrInvalidNodeId invalid node id error. ErrInvalidNodeId = errors.New("invalid node id") )
Functions ¶
Types ¶
type Config ¶
type Config struct { StartTime time.Time // start time, default is 2020-06-01 00:00:00 UTC/GMT +8.00 MaxTolerateMillis int64 // max tolerated clock fallback milliseconds LastGenerateTime func() (time.Time, error) // last id generation time, default is the current time NodeId func() (int64, error) // node id }
Config snowflake generator config.
type Snowflake ¶
type Snowflake struct {
// contains filtered or unexported fields
}
Snowflake distributed unique id generator based on snowflake algorithm.
func NewSnowflake ¶
NewSnowflake new a snowflake generator.
Click to show internal directories.
Click to hide internal directories.