snowflake

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

Go Reference Go Version License Disgo Version Disgo Discord

snowflake

snowflake is a golang library for parsing snowflake IDs from discord. This package provides a custom snowflake type which has various utility methods for parsing snowflake IDs.

Installing
go get github.com/DisgoOrg/snowflake

Usage


id := Snowflake("123456789012345678")

// deconstructs the snowflake ID into its components timestamp, worker ID, process ID, and increment
id.Deconstruct()

// time.Time when the snowflake was generated
id.Time()

// returns the string representation of the snowflake ID
id.String()

// returns the int64 representation of the snowflake ID
id.Int64()

// returns a new snowflake with worker ID, process ID, and increment set to 0
// this can be used for various pagination requests to the discord api
id = NewSnowflake(time.Now())

// returns the fmt.Stringer as a Snowflake
id = ParseString(...)

// returns the int64 as a Snowflake
id = ParseInt64(123456789012345678)

// returns the uint64 as a Snowflake
id = ParseUInt64(123456789012345678)

// returns a snowflake from an environment variable
id = GetSnowflakeEnv("guild_id")

License

Distributed under the License. See LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Epoch int64 = 1420070400000

Functions

This section is empty.

Types

type DeconstructedSnowflake

type DeconstructedSnowflake struct {
	Time      time.Time
	WorkerID  int64
	ProcessID int64
	Increment int64
}

DeconstructedSnowflake contains the properties used by Discord for each CommandID

type Snowflake

type Snowflake string

Snowflake is a general utility type around discord's IDs

func GetSnowflakeEnv added in v1.0.1

func GetSnowflakeEnv(key string) Snowflake

GetSnowflakeEnv returns a new Snowflake from an environment variable

func NewSnowflake

func NewSnowflake(timestamp time.Time) Snowflake

NewSnowflake returns a new Snowflake based on the given time.Time

func ParseInt64 added in v1.0.3

func ParseInt64(i int64) Snowflake

ParseInt64 parses an int64 into a Snowflake

func ParseString added in v1.0.4

func ParseString(str fmt.Stringer) Snowflake

ParseString parses a fmt.Stringer into a Snowflake

func ParseUInt64 added in v1.0.3

func ParseUInt64(i uint64) Snowflake

ParseUInt64 parses an uint64 into a Snowflake

func (Snowflake) Int64

func (s Snowflake) Int64() int64

Int64 returns the int64 representation of the Snowflake

func (Snowflake) String

func (s Snowflake) String() string

String returns the string representation of the Snowflake

func (Snowflake) Time

func (s Snowflake) Time() time.Time

Time returns the time.Time when the snowflake was created

Jump to

Keyboard shortcuts

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