shortid

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Copyright (c) 2023 H0llyW00dzZ

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(length int) (string, error)

Generate creates a cryptographically secure, URL-friendly short ID of a specified length. The ID is generated using random bytes, which are then base64 URL encoded to ensure they can be safely used in URLs. The length parameter specifies the desired length of the final encoded ID. If the length is not a multiple of 4, the function compensates to ensure the final ID has the correct length.

The function returns the generated short ID or an error if the random byte generation fails.

Example usage:

id, err := shortid.Generate(10)
if err != nil {
    log.Fatalf("Failed to generate short ID: %v", err)
}
fmt.Println("Generated short ID:", id)

Types

This section is empty.

Jump to

Keyboard shortcuts

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