utilgo.mau.fi/util/random Index | Files

package random

import "go.mau.fi/util/random"

Index

Functions

func Bytes

func Bytes(n int) []byte

Bytes generates the given amount of random bytes using crypto/rand, and panics if it fails.

func GetTokenPrefix

func GetTokenPrefix(token string) string

GetTokenPrefix parses the given token generated with Token, validates the checksum and returns the prefix namespace.

func IsToken

func IsToken(namespace, token string) bool

IsToken checks if the given token is a valid token generated with Token with the given namespace..

func String

func String(n int) string

String generates a random string of the given length.

func StringBytes

func StringBytes(n int) []byte

StringBytes generates a random string of the given length and returns it as a byte array.

func Token

func Token(namespace string, randomLength int) string

Token generates a GitHub-style token with the given prefix, a random part, and a checksum at the end. The format is `prefix_random_checksum`. The checksum is always 6 characters.

Source Files

bytes.go string.go

Version
v0.8.6 (latest)
Published
Mar 16, 2025
Platform
linux/amd64
Imports
5 packages
Last checked
1 week ago

Tools for package owners.