Documentation ¶
Overview ¶
Copyright (c) 2023 H0llyW00dzZ
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
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.
Click to show internal directories.
Click to hide internal directories.