snowflake

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

Quick Start

Generate an ID


import (
  "fmt"
  "github.com/abulo/ratel/v2/snowflake"
)

func ExampleGenInt64ID() {
  id := snowflake.CommonConfig.GenInt64ID()
  fmt.Printf("id generated: %v", id)
}

Documentation

Index

Constants

View Source
const (
	//StartTimeEnvName is the env key for ID generating start time
	StartTimeEnvName = "SNOWFLAKEID_START_TIME"
	//MachineIDEnvName is the env key for machine id
	MachineIDEnvName = "SNOWFLAKEID_MACHINE_ID"
)

Variables

View Source
var BenchmarkConfig = ConstructConfig(40, 15, 8)

BenchmarkConfig is a high performance setting for benchmark

40 bits timestamp
15 bits seq
8  bits machine id
View Source
var CommonConfig = ConstructConfig(40, 7, 16)

CommonConfig is the recommended setting for most applications

40 bits timestamp
7  bits seq
16 bits machine id

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

func ConstructConfig(timeBits, seqBits, machineBits uint) *Config

ConstructConfig creates an instance of FastIDConfig with the given settings

func ConstructConfigWithMachineID

func ConstructConfigWithMachineID(timeBits, seqBits, machineBits uint, machineID int64) *Config

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

func (c *Config) GenInt64ID() int64

GenInt64ID generates unique int64 IDs with the setting in the methond owner

func (*Config) GetSeqFromID

func (c *Config) GetSeqFromID(id int64) int64

GetSeqFromID extracts seq number from an existing ID

func (*Config) GetTimeFromID

func (c *Config) GetTimeFromID(id int64) int64

GetTimeFromID extracts timestamp from an existing ID

Jump to

Keyboard shortcuts

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