snowflake

package
v1.1.22 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package snowflake provides a very simple Twitter snowflake generator and parser.

Index

Constants

This section is empty.

Variables

View Source
var (
	Epoch    int64 = 1288834974657
	NodeBits uint8 = 10
	StepBits uint8 = 12
)
View Source
var (
	ErrInvalidBase58 = errors.New("invalid base58")
	ErrInvalidBase32 = errors.New("invalid base32")
)

Functions

This section is empty.

Types

type ID

type ID int64

func ParseBase32

func ParseBase32(b []byte) (ID, error)

func ParseBase58

func ParseBase58(b []byte) (ID, error)

func (ID) Base2

func (f ID) Base2() string

func (ID) Base32

func (f ID) Base32() string

func (ID) Base36

func (f ID) Base36() string

func (ID) Base58

func (f ID) Base58() string

func (ID) Int64

func (f ID) Int64() int64

以下所有方法完全不变,100%保留你的代码

func (ID) IntBytes

func (f ID) IntBytes() [8]byte

func (ID) MarshalJSON

func (f ID) MarshalJSON() ([]byte, error)

func (ID) Node

func (f ID) Node() int64

func (ID) Step

func (f ID) Step() int64

func (ID) String

func (f ID) String() string

func (ID) Time

func (f ID) Time() int64

func (*ID) UnmarshalJSON

func (f *ID) UnmarshalJSON(b []byte) error

type JSONSyntaxError

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

func (JSONSyntaxError) Error

func (j JSONSyntaxError) Error() string

type Node

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

func NewNode

func NewNode(node int64) (*Node, error)

NewNode 移除重复全局变量赋值,规范简洁

func (*Node) Generate

func (n *Node) Generate() ID

Generate 核心逻辑完全保留,无任何修改

func (*Node) GetNow

func (n *Node) GetNow() int64

GetNow 高性能时间获取(保留你想要的写法)

Jump to

Keyboard shortcuts

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