snowflake

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: BSD-3-Clause Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultGenerator = NewGen(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))

DefaultGenerator is a Generator with the epoch set to January 1, 2021 at 00:00 UTC

View Source
var DefaultSmallGenerator = NewSmallGen(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))

DefaultSmallGenerator is a SmallGenerator with the epoch set to January 1, 2021 at 00:00 UTC

Functions

This section is empty.

Types

type Generator

type Generator struct {
	Epoch time.Time
	// contains filtered or unexported fields
}

Generator holds info needed for generating custom snowflakes

func NewGen

func NewGen(epoch time.Time) *Generator

NewGen returns a new generator

func (*Generator) Get

func (g *Generator) Get() Snowflake

Get gets a new snowflake

func (*Generator) GetFromTime

func (g *Generator) GetFromTime(t time.Time) Snowflake

GetFromTime gets a snowflake, with only the time field set, that parses as the given time

func (*Generator) Parse

func (g *Generator) Parse(s Snowflake) (t time.Time, err error)

Parse parses the given snowflake into a timestamp

type ID

type ID = Snowflake

ID is an alias for Snowflake

type SmallGenerator added in v2.1.0

type SmallGenerator struct {
	Epoch time.Time
	// contains filtered or unexported fields
}

SmallGenerator holds info needed for generating custom snowflakes

func NewSmallGen added in v2.1.0

func NewSmallGen(epoch time.Time) *SmallGenerator

NewSmallGen returns a new small generator

func (*SmallGenerator) Get added in v2.1.0

func (g *SmallGenerator) Get() SmallSnowflake

Get gets a new snowflake

func (*SmallGenerator) GetFromTime added in v2.1.0

func (g *SmallGenerator) GetFromTime(t time.Time) SmallSnowflake

GetFromTime gets a snowflake, with only the time field set, that parses as the given time

func (*SmallGenerator) Parse added in v2.1.0

func (g *SmallGenerator) Parse(s SmallSnowflake) (t time.Time, err error)

Parse parses the given snowflake into a timestamp

type SmallID added in v2.1.0

type SmallID = SmallSnowflake

SmallID is an alias for SmallSnowflake

type SmallSnowflake added in v2.1.0

type SmallSnowflake uint32

SmallSnowflake is a uint32-sized ID

func ParseSmallSnowflake added in v2.1.0

func ParseSmallSnowflake(s string) (SmallSnowflake, error)

ParseSmallSnowflake parses a string into a small snowflake, if possible

func (SmallSnowflake) String added in v2.1.0

func (s SmallSnowflake) String() string

type Snowflake

type Snowflake uint64

Snowflake is an ID generated by a Generator

func (Snowflake) Int

func (s Snowflake) Int() int64

Int returns the integer version of a snowflake

func (Snowflake) String

func (s Snowflake) String() string

func (Snowflake) ToTime

func (s Snowflake) ToTime(epoch time.Time) time.Time

ToTime converts the snowflake to a timestamp

Jump to

Keyboard shortcuts

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