snowflake

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2022 License: BSD-2-Clause Imports: 3 Imported by: 0

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

func NodeId

func NodeId(nodeId int64) func() (int64, error)

NodeId returns the node id constructor.

func Parse

func Parse(id int64, startTime ...time.Time) map[string]int64

Parse parses snowflake id.

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

func NewSnowflake(c *Config) (*Snowflake, error)

NewSnowflake new a snowflake generator.

func (*Snowflake) NextId

func (s *Snowflake) NextId() (int64, error)

NextId generates snowflake id.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL