snowflake

package
v0.3.19 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package snowflake provides a unique ID generation based on Twitter Snowflake algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NumberSnowflake

type NumberSnowflake struct {
	*Snowflake
}

func NewNumber

func NewNumber(opts ...Option) *NumberSnowflake

func (NumberSnowflake) Generate

func (n NumberSnowflake) Generate() int64

func (NumberSnowflake) Validate

func (n NumberSnowflake) Validate(t int64) bool

type Option

type Option = func(options *Options)

type Options

type Options struct {
	Node int64
}

type Snowflake

type Snowflake struct {
	// contains filtered or unexported fields
}

Snowflake represents a Snowflake generator with a unique generator.

func New

func New(opts ...Option) *Snowflake

New creates a new Snowflake generator with a unique generator.

func (Snowflake) GenerateNumber

func (s Snowflake) GenerateNumber() int64

GenerateNumber generates a new Snowflake ID as an int64.

func (Snowflake) GenerateString

func (s Snowflake) GenerateString() string

GenerateString generates a new Snowflake ID as a string.

func (Snowflake) Name

func (s Snowflake) Name() string

Name returns the name of the generator.

func (Snowflake) Size

func (s Snowflake) Size() int

Size returns the bit size of the generated Snowflake ID.

func (Snowflake) ValidateNumber

func (s Snowflake) ValidateNumber(id int64) bool

ValidateNumber checks if the provided ID is a valid Snowflake ID (int64).

func (Snowflake) ValidateString

func (s Snowflake) ValidateString(id string) bool

ValidateString checks if the provided ID is a valid Snowflake ID (string).

type StringSnowflake

type StringSnowflake struct {
	*Snowflake
}

func NewString

func NewString(opts ...Option) *StringSnowflake

func (StringSnowflake) Generate

func (s StringSnowflake) Generate() string

func (StringSnowflake) Validate

func (s StringSnowflake) Validate(id string) bool

Jump to

Keyboard shortcuts

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