Skip to content

Latest commit

 

History

History
52 lines (42 loc) · 2.57 KB

README.md

File metadata and controls

52 lines (42 loc) · 2.57 KB

Discord Goflake

CircleCI Codacy Badge Codacy Badge 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.