dgoflake

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2020 License: Apache-2.0 Imports: 3 Imported by: 1

README

Discord Goflake

CircleCI Codacy grade Codacy coverage Godoc reference GitHub release (latest by date)

Discord Goflake is a simple and fast Go utility library for handling Discord snowflake IDs.

It contains utilities such as parsing snowflakes and retrieving timestamps from snowflakes.

Tutorial

Retrieving timestamp from a raw string ID

snowflake, err := dgoflake.ParseString("577685297450582016")
if err == nil {
	timestamp := snowflake.Timestamp()
}

Converting epoch milliseconds timestamp to snowflake

snowflake, err := dgoflake.ParseEpochMilli(1557801521446)

See the godocs for the full reference.

Benchmarks

Snowflake to Timestamp              1000000000           0.590 ns/op
UInt64 to Snowflake                 1000000000	         0.295 ns/op
String to Snowflake          	    14054162	         86.3 ns/op
Epoch Milliseconds to Snowflake     1000000000	         0.633 ns/op
Epoch Seconds to Snowflake          71313086	         17.0 ns/op

License

Copyright ©2019 Hassie.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package dgoflake provides utilities for fast handling of Discord snowflakes.

Index

Constants

View Source
const DiscordEpoch uint64 = 1420070400000

DiscordEpoch is Discord's epoch in milliseconds.

Variables

This section is empty.

Functions

This section is empty.

Types

type Snowflake

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

Snowflake is the type for a Discord snowflake.

func ParseEpochMilli

func ParseEpochMilli(epoch uint64) (*Snowflake, error)

ParseEpochMilli parses an epoch milliseconds timestamp to a snowflake.

func ParseEpochSec

func ParseEpochSec(epoch uint64) (*Snowflake, error)

ParseEpochSec parses an epoch seconds timestamp to a snowflake.

func ParseInt

func ParseInt(id uint64) *Snowflake

ParseInt parses an int to a snowflake.

func ParseString

func ParseString(id string) (*Snowflake, error)

ParseString parses a string to a snowflake.

func (*Snowflake) Increment

func (s *Snowflake) Increment() uint64

Increment gets the increment number for this snowflake.

func (*Snowflake) Int64

func (s *Snowflake) Int64() int64

Int64 gets the snowflake as an int64.

func (*Snowflake) InternalProcessID

func (s *Snowflake) InternalProcessID() uint64

InternalProcessID gets the internal process ID for this snowflake.

func (*Snowflake) InternalWorkerID

func (s *Snowflake) InternalWorkerID() uint64

InternalWorkerID gets the internal worker ID for this snowflake.

func (*Snowflake) String

func (s *Snowflake) String() string

String gets the snowflake as a string.

func (*Snowflake) Timestamp

func (s *Snowflake) Timestamp() time.Time

Timestamp converts the snowflake to a timestamp.

func (*Snowflake) UInt64

func (s *Snowflake) UInt64() uint64

UInt64 gets the snowflake as a uint64.

Jump to

Keyboard shortcuts

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