uid

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 License: MIT Imports: 5 Imported by: 28

README

UID (Unique ID) Open in Gitpod

Tests Status Go Report Card PkgGoDev

THis package generates unique identifying strings. Largest attention is paid on human friendly unique identifiers (dated digits).

Installation

go get -u https://github.com/gouniverse/uid

Usage

// HumanUid generates a UUID (32 digits) Format: YYYYMMDD-HHMM-SSMM-MMMMNNNRRRRRRRRR
humanUID := uid.HumanUid()

// NanoUid generates a UID (23 digits) Format: YYYYMMDD-HHMMSS-MMMMMM-NNN
humanUID := uid.NanoUid()

// MicroUid generates a UID (20 digits) Format: YYYYMMDD-HHMMSS-MMMMMM
microUID := uid.MicroUid()

// SecUid generates UID (14 digits) Format: YYYYMMDD-HHMMSS
secondsUID := uid.SecUid()

Supported UID Types

It supports several types of unique identifiers.

The type you want to use will usually depends on two considerations:

  1. How random you want it to be? The longer the identifier, the more the chances of collision reduce
  2. How long you want the identifier to be? The longer the identifier, reduces the readability, as well as the storage space to store it.

For most of the user cases a Micro UUID (20 chars) should be fine. A human UUID (32 chars) should be avoided where a human is involved as too "mind bogging" to work with.

  1. Human UUID (32 digits)

    Format: YYYYMMDD-HHMM-SSMM-MMMMNNNRRRRRRRRR

    2017111908492665991498485465 (with dashes: 20171119-0849-2665-991498485465)

  2. Nano UID (23 digits)

    Format: YYYYMMDD-HHMMSS-MMMMMM-NNN

    Examples:

    20171119084926659914984 (with dashes: 20171119-084926-659914-984)

  3. Micro UID (20 digits)

    Format: YYYYMMDD-HHMMSS-MMMMMM

    Examples:

    20171119084926659914 (with dashes: 20171119-084926-659914)

  4. Seconds UID (14 digits)

    Format: YYYYMMDD-HHMMSS

    Examples:

    20171119084926 (with dashes: 20171119-084926)

  5. Timestamp (10 digits) Unit timestamp, seconds precision

    Format: 1234567890

    Examples:

    1704524414

  6. TimestampMicro (16 digits) Unit timestamp, microseconds precision

    Format: 1234567890123456

    Examples:

    1704524414548721

  7. TimestampNano (19 digits) Unit timestamp, nanoseconds precision

    Format: 1234567890123456789

    Examples:

    1704524414548721308

  8. Uuid (32 characters) Random V4 UUID. UUID (Universally Unique IDentifier), also known as GUID (Globally Unique IDentifier)

    Format: abcdef1234567890abcdef1234567890

    Examples:

    459e2999bd071151a23d643da42c2cc2

Change Log

2024.01.06 - Added Timestamp and Uuid functions 2021.12.19 - Master branch changed to main 2021.12.19 - Added tests

Similar Packages

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HumanUid

func HumanUid() string

HumanUid generates a UUID (32 digits) Format: YYYYMMDD-HHMM-SSMM-MMMMNNNRRRRRRRRR

func MicroUid

func MicroUid() string

MicroUid generates a UID (20 digits) Format: YYYYMMDD-HHMMSS-MMMMMM

func NanoUid

func NanoUid() string

NanoUid generates a UID (23 digits) Format: YYYYMMDD-HHMMSS-MMMMMM-NNN

func SecUid

func SecUid() string

SecUid generates UID (14 digits) Format: YYYYMMDD-HHMMSS

func Timestamp

func Timestamp() string

func TimestampMicro

func TimestampMicro() string

func TimestampNano

func TimestampNano() string

func Uuid

func Uuid() string

func UuidFormatted

func UuidFormatted() string

func UuidV1

func UuidV1() string

func UuidV1Formatted

func UuidV1Formatted() string

func UuidV3

func UuidV3(namespace string, data []byte) (string, error)

func UuidV3Formatted

func UuidV3Formatted(namespace string, data []byte) (string, error)

func UuidV4

func UuidV4() string

func UuidV4Formatted

func UuidV4Formatted() string

func UuidV5

func UuidV5(namespace string, data []byte) (string, error)

func UuidV5Formatted

func UuidV5Formatted(namespace string, data []byte) (string, error)

func UuidV6

func UuidV6() string

func UuidV6Formatted

func UuidV6Formatted() string

func UuidV7

func UuidV7() string

func UuidV7Formatted

func UuidV7Formatted() string

Types

This section is empty.

Jump to

Keyboard shortcuts

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