snowflake

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package snowflake providers a unique ID generator based on Twitter's Snowflake ID.

Index

Constants

View Source
const (
	Epoch int64 = 1288834974657
)

Variables

View Source
var (
	// NodeBits is the number of bits to use for Node.
	NodeBits uint8 = 10
	// StepBits is the number of bits to use for Step.
	StepBits uint8 = 12
)

Functions

This section is empty.

Types

type ID

type ID int64

ID is a unique ID

func ParseBase64

func ParseBase64(id string) (ID, error)

Parsebase64 parses a base64 encoded string into an Snowflake ID.

func ParseBytes

func ParseBytes(id []byte) (ID, error)

ParseString parses a string into an Snowflake ID.

func ParseInt64

func ParseInt64(id int64) ID

ParseInt64 parses an int64 into an Snowflake ID.

func (ID) Base64

func (i ID) Base64() string

Base64 returns the ID as a base64 encoded string

func (ID) Bytes

func (i ID) Bytes() []byte

Bytes returns the ID as a byte slice

func (ID) Int64

func (i ID) Int64() int64

Int64 returns the ID as an int64

func (ID) ProtoMessage

func (i ID) ProtoMessage() *pb.Snowflake

ProtoMessage returns the ID as a protobuf Snowflake message.

func (ID) String

func (i ID) String() string

String returns the ID as a string

type Node

type Node interface {
	Generate() ID
}

Node is an interface for generating unique Snowflake IDs.

func New

func New(id int64) (Node, error)

New returns a new Node that can be used to generate Snowflake IDs.

Jump to

Keyboard shortcuts

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