id

package
v0.0.57-rc.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package id generates unique random strings. It however should not be used for cryptography purposes.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() string

New returns a new random string.

Example
package main

import (
	"fmt"

	"github.com/komuw/ong/id"
)

func main() {
	fmt.Println(id.New())
}
Output:

func Random

func Random(n int) string

Random generates a random string of size n.

If n < 1 or significantly large, it is set to reasonable bounds. It uses `crypto/rand` but falls back to `math/rand` on error.

Example
package main

import (
	"fmt"

	"github.com/komuw/ong/id"
)

func main() {
	size := 34
	s := id.Random(size)
	if len(s) != size {
		panic("mismatched sizes")
	}
	fmt.Println(s)
}
Output:

Types

type UUID added in v0.0.56

type UUID [16]byte

UUID represents a universally unique identifier. See UUID4 and UUID8

func UUID4 added in v0.0.56

func UUID4() UUID

UUID4 generates a version 4 UUID. It is not correlated with timestamp, thus, when used as the identifief of an object, it does not leak its creation time. On the other hand, this means that it has poor database index locality unlike UUID8.

See UUID8 and New

It panics on error.

func UUID8 added in v0.0.56

func UUID8() UUID

UUID8 generates a version 8 UUID. Version 8 provides an RFC-compatible format for experimental/specific use cases.

This one is mostly like version 7 except it uses nanosecond precision instead of millisecond. It is correlated with timestamp, thus, when used as the identifief of an object, it has good database locality. On the other hand, this means that it can leak the object's creation time unlike UUID4.

See UUID4 and New

It panics on error.

func (UUID) Bytes added in v0.0.56

func (u UUID) Bytes() []byte

Bytes returns the bytes that undely the UUID.

func (UUID) String added in v0.0.56

func (u UUID) String() string

Jump to

Keyboard shortcuts

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