uniqid

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

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

Go to latest
Published: Mar 22, 2026 License: Apache-2.0 Imports: 4 Imported by: 13

README

go-uniqid

Share on X Share on Reddit

CI Tests Go Reference

Unique ID generator for Go, inspired by PHP's uniqid(). Goroutine-safe.

Install

go get github.com/mintance/go-uniqid

Usage

package main

import (
    "fmt"
    "github.com/mintance/go-uniqid"
)

func main() {
    fmt.Println(uniqid.New())                              // "6601a3d800001"
    fmt.Println(uniqid.NewWithPrefix("usr_"))               // "usr_6601a3d800002"
    fmt.Println(uniqid.NewWithEntropy())                    // "6601a3d8000035.82749103"
    fmt.Println(uniqid.NewWithPrefixAndEntropy("sess_"))    // "sess_6601a3d8000042.19384756"
}

API

Function Description
New() 13-char hex ID (timestamp + counter)
NewWithPrefix(prefix) Prefixed hex ID
NewWithEntropy() 23-char ID with random decimal suffix
NewWithPrefixAndEntropy(prefix) Prefixed ID with entropy

All functions are safe for concurrent use.

License

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() string

New returns a 13-character unique ID based on the current timestamp and an atomic counter.

func NewWithEntropy

func NewWithEntropy() string

NewWithEntropy returns a 23-character unique ID with additional random entropy.

func NewWithPrefix

func NewWithPrefix(prefix string) string

NewWithPrefix returns a unique ID prefixed with the given string.

func NewWithPrefixAndEntropy

func NewWithPrefixAndEntropy(prefix string) string

NewWithPrefixAndEntropy returns a unique ID with a prefix and additional random entropy.

Types

This section is empty.

Jump to

Keyboard shortcuts

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