Skip to content

twharmon/gouid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gouid

Go Reference codecov

Use Gouid to create cryptographically secure random IDs. IDs can be byte slices or strings, both generated with just one allocation (see benchmarks below).

Documentation

For full documentation see pkg.go.dev.

Example

package main

import (
	"fmt"
	
	"github.com/twharmon/gouid"
)

func main() {
	a := gouid.String(8, gouid.Secure32Char)
	fmt.Println(a) // mp1nq34p

	b := gouid.String(16, gouid.Secure64Char)
	fmt.Println(b) // h-SoemLKa_QtoXgh

	c := gouid.Bytes(16)
	fmt.Println(c) // [244 188 217 137 122 245 94 126 80 119 87 170 6 178 228 179]
}

Benchmarks

goos: linux
goarch: amd64
pkg: github.com/twharmon/gouid
cpu: AMD Ryzen 7 7840HS w/ Radeon 780M Graphics     
BenchmarkString8     	 337.6 ns/op	       8 B/op	       1 allocs/op
BenchmarkString16    	 359.1 ns/op	      16 B/op	       1 allocs/op
BenchmarkString32    	 363.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkBytes8      	 327.0 ns/op	       8 B/op	       1 allocs/op
BenchmarkBytes16     	 334.0 ns/op	      16 B/op	       1 allocs/op
BenchmarkBytes32     	 334.7 ns/op	      32 B/op	       1 allocs/op

Contribute

Make a pull request.

About

Fast, dependable universally unique ids

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages