snowflake

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Snowflake ID generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Id

func Id() (id string)

Generate Snowflake Id

The id consists of [64 bits long] + [6 digits machine_code] The 64 bits long consists of: [sign bit (1 bit)] + [timestamp (49 bits, ~1487.583 years)] + [sequenceNo (14 bits, 0~16383)]

The max value of Long is 9223372036854775807, which is a string with 19 characters, so the generated id will be of at most 25 characters

This func is thread-safe

func IdPrefix

func IdPrefix(prefix string) (id string)

func SetMachineCode

func SetMachineCode(code int) error

Overwrite the randomly generated machine code, machine code must be between 0 and 999999, at most 6 digits.

Types

This section is empty.

Jump to

Keyboard shortcuts

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