tinyid

package module
v0.0.0-...-fcb0f9c Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: MIT Imports: 3 Imported by: 0

README

tinyid

A super tiny, high performant fast Go unique string ID generator:

  • Safe: Utilizes cryptographically strong random APIs to ensure security.
  • Compact: Employs a larger alphabet than UUID (A-Za-z0-9_-), potentially reducing ID size from 36 to 31.
  • Efficient: Benchmarks at approximately 489.3 ns/op for generating IDs.
  • 100% TC: Achieves full test coverage.
  • Small: <80 LoC.

Benchmark:

goos: darwin
goarch: arm64
pkg: github.com/ArchishmanSengupta/tinyid
BenchmarkNewTinyID-10         	 2419586	       489.3 ns/op
BenchmarkGenerateTinyID-10    	 2457799	       489.7 ns/op
PASS
ok  	github.com/ArchishmanSengupta/tinyid	3.535s

Test Coverage:

go test -v
=== RUN   TestGenerateTinyID
--- PASS: TestGenerateTinyID (0.00s)
=== RUN   TestNewTinyID
--- PASS: TestNewTinyID (0.00s)
PASS
ok  	github.com/ArchishmanSengupta/tinyid	0.420s

Use:

id, err := tinyid.NewTinyID()
	if err != nil {
		fmt.Print("some problem")
}
fmt.Println("Generated ID:", id)

Documentation

Index

Constants

View Source
const (
	// Default is the default alphabet for TinyIDs.
	DefaultAlphabet = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
	// DefaultSize is the default size for Tiny IDs.
	DefaultSize = 31
)

Represent the default alphabet and size for the generated tiny IDs.

Variables

This section is empty.

Functions

func NewTinyID

func NewTinyID() (string, error)

NewTinyID generates a random string with default settings.

Types

type GenerateBytes

type GenerateBytes func(step int) ([]byte, error)

Generate Bytes represents random bytes buffer 'step' parameter representing the number of bytes to generate and returns a byte slice and an error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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