id

package
v0.0.97 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package id generates unique random identifiers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() string

New returns a new random string consisting of a legible character set. It is not suitable for cryptographic uses.

Also see UUID4 and UUID8

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 consisting of a legible character set. If n < 1 or significantly large, it is set to reasonable bounds. It is not suitable for cryptographic uses.

Also see UUID4 and UUID8

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. Also 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. It might also be a good use as a shard key.

Also 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.

Also 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

String implements fmt.Stringer for uuid.

Jump to

Keyboard shortcuts

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