Categorygithub.com/kecci/int-uid
modulepackage
0.1.2
Repository: https://github.com/kecci/int-uid.git
Documentation: pkg.go.dev

# README

GitHub Go Report Card GitHub issues GitHub code size in bytes made-with-Go FOSSA Status CircleCI

int-uid

int-uid

Experimental project to generate integer unique identifier.

Docs: https://pkg.go.dev/github.com/kecci/int-uid

Installation

$ go get github.com/kecci/int-uid

Usage

examples main.go:

package main

import (
	"fmt"
	"time"

	uid "github.com/kecci/int-uid"
)

func main() {
	// Unix Nano
	fmt.Println("UnixNano")
	unix := uid.New().UnixNano()
	unixReverse := unix.Reverse()
	fmt.Println(unix.Int64())
	fmt.Println(unixReverse.Int64())

	// Snowflake
	fmt.Println("Snowflake")
	snow := uid.New().Snowflake()
	snowReverse := snow.Reverse()
	fmt.Println(snow.Int64())
	fmt.Println(snowReverse.Int64())

	// Sonyflake
	fmt.Println("Sonyflake")
	sony := uid.New().Sonyflake(time.Time{})
	sonyReverse := sony.Reverse()
	fmt.Println(sony.Int64())
	fmt.Println(sonyReverse.Int64())
}

output :

UnixNano
1614436846108942000
2498016486344161
Snowflake
1365673231834419200
29144381323765631
Sonyflake
3999050837534991611
1161994357380509993

Data Types

There are several functions to get int-uid.

FuncBitLengthGo Data TypeSQL Data TypeExample
UnixNano()64 bit19 Characterint64BigInt1614432967521585000
UnixNano().Reverse()64 bit16 Characterint64BigInt1261257692344161
Snowflake()64 bit19 Characterint64BigInt1365656963861450752
Snowflake().Reverse()64 bit19 Characterint64BigInt2570541683696565631
Sonyflake(time.Time)64 bit19 Characterint64BigInt3999050837534991611
Sonyflake(time.Time).Reverse()64 bit19 Characterint64BigInt1161994357380509993

Benchmark

goos: darwin
goarch: amd64
pkg: github.com/kecci/int-uid
BenchmarkUnixNano/UnixNano()-8          		1000000000      0.000001 ns/op      0 B/op      0 allocs/op
BenchmarkUnixNano/UnixNano().Reverse()-8        1000000000      0.000005 ns/op      0 B/op      0 allocs/op
BenchmarkSnowflake/Snowflake()-8                1000000000      0.000002 ns/op      0 B/op      0 allocs/op
BenchmarkSnowflake/Snowflake().Reverse()-8      1000000000      0.000002 ns/op      0 B/op      0 allocs/op
BenchmarkSonyflake/Sonyflake()-8                1000000000      0.000049 ns/op      0 B/op      0 allocs/op
BenchmarkSonyflake/Sonyflake().Reverse()-8      1000000000      0.000047 ns/op      0 B/op      0 allocs/op
PASS
coverage: 100.0% of statements
ok      github.com/kecci/int-uid        0.179s

License

FOSSA Status

# Packages

No description provided by the author

# Functions

New initiate UID.

# Structs

UID basic info.

# Type aliases

ID custom type used for int-uid.