Documentation
¶
Overview ¶
snowflake is a distributed, k-ordered unique ID generator.
Under 64 bits (Long Integer) Lock-free (using atomic CAS) Decentralized and no coordination needed Docker friendly
根据 https://github.com/beinan/fastid 修改所得
Index ¶
Constants ¶
View Source
const ( //StartTimeEnvName is the env key for ID generating start time StartTimeEnvName = "FASTID_START_TIME" //MachineIDEnvName is the env key for machine id MachineIDEnvName = "FASTID_MACHINE_ID" )
Variables ¶
View Source
var ( // BenchmarkConfig is a high performance setting for benchmark // 40 bits timestamp // 15 bits seq // 8 bits machine id BenchmarkConfig = ConstructConfig(40, 15, 8) // CommonConfig is the recommended setting for most applications // 40 bits timestamp // 7 bits seq // 16 bits machine id CommonConfig = ConstructConfig(40, 7, 16) // JsConfig 兼容JS前台整型数据正常显示,支持的范围 -9007199254740992 ~ +9007199254740992 // 40 bits timestamp // 7 bits seq // 8 bits machine id JsConfig = ConstructConfig(40, 7, 8) )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config maintains the settings for id generating
func ConstructConfig ¶
ConstructConfig creates an instance of FastIDConfig with the given settings
func ConstructConfigWithMachineID ¶
ConstructConfigWithMachineID creates an config with machine id, in case you don't want to use the lower 16 bits of the IP address.
func (*Config) GenInt64ID ¶
GenInt64ID generates unique int64 IDs with the setting in the methond owner
func (*Config) GetSeqFromID ¶
GetSeqFromID extracts seq number from an existing ID
func (*Config) GetTimeFromID ¶
GetTimeFromID extracts timestamp from an existing ID
Click to show internal directories.
Click to hide internal directories.