util

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StringBuilderNumberedString = NewStringBuilder().
	WithUpperLetters().
	WithLowerLetters().
	WithNumbers()

StringBuilderNumberedString is a pre-configured StringBuilder for generating random strings with uppercase letters, lowercase letters, and numbers.

View Source
var StringBuilderPassword = NewStringBuilder().
	WithUpperLetters().
	WithLowerLetters().
	WithNumbers().
	WithSpecialCharacters()

StringBuilderPassword is a pre-configured StringBuilder for generating random passwords with uppercase letters, lowercase letters, numbers, and special characters.

View Source
var StringBuilderString = NewStringBuilder().
	WithUpperLetters().
	WithLowerLetters()

StringBuilderString is a pre-configured StringBuilder for generating random strings with uppercase and lowercase letters.

Functions

func IsDebugEnabled

func IsDebugEnabled() (bool, string)

func Poll added in v0.7.0

func Poll(ctx context.Context, fn PollFunc, opts PollOptions) error

Poll executes the given function `fn` until it returns no error, or until the configured number of tries, timeout, or context cancellation is reached.

The function respects the provided context for cancellation. If `opts.Timeout` is non-zero, the timeout is applied in addition to the provided context.

Types

type ContextAware added in v0.1.0

type ContextAware interface {
	Context() context.Context
}

type DefaultURLComparer added in v0.1.0

type DefaultURLComparer struct{}

DefaultURLComparer is the default implementation of URLComparer.

func (DefaultURLComparer) EqualStrings added in v0.1.0

func (c DefaultURLComparer) EqualStrings(a, b string) (bool, error)

EqualStrings parses and compares two URL strings.

func (DefaultURLComparer) EqualURLs added in v0.1.0

func (c DefaultURLComparer) EqualURLs(a, b *url.URL) bool

EqualURLs compares two url.URL instances for equality after normalization.

type PollFunc added in v0.7.0

type PollFunc func() error

PollFunc is the function to be executed by the Poll function. It should return an error to indicate a failure and that it should be retried. A nil error indicates success.

type PollOptions added in v0.7.0

type PollOptions struct {
	// Tries is the maximum number of times to try the function.
	// If Tries is 0, it will retry until Timeout is reached.
	Tries int
	// Delay is the time to wait between retries.
	// If Delay is 0, binary exponential backoff is used, starting at 2 seconds.
	Delay time.Duration
	// Timeout is the maximum total time to spend retrying.
	// If Timeout is 0, there is no time limit.
	Timeout time.Duration
}

PollOptions configures the behavior of the Poll function.

type StringBuilder added in v0.7.0

type StringBuilder struct {
	// contains filtered or unexported fields
}

StringBuilder is a builder for configuring and generating custom random strings. By default, no character sets are included. You must add at least one using With* methods. Mutations like AsHexString or AsBinaryString can be applied to transform the output after generation.

func NewStringBuilder added in v0.7.0

func NewStringBuilder() *StringBuilder

NewStringBuilder creates a new StringBuilder with no default character sets.

func (*StringBuilder) AsBinaryString added in v0.7.0

func (sb *StringBuilder) AsBinaryString() *StringBuilder

AsBinaryString sets the mutation to convert the generated string to its binary representation. This transforms each byte into an 8-bit binary string, multiplying the length by 8.

func (*StringBuilder) AsHexString added in v0.7.0

func (sb *StringBuilder) AsHexString() *StringBuilder

AsHexString sets the mutation to convert the generated string to its hexadecimal representation. This transforms each byte of the string into two hex characters, doubling the length.

func (*StringBuilder) Generate added in v0.7.0

func (sb *StringBuilder) Generate(length int) (string, error)

Generate creates a random string of the specified length using the configured character set. If no character sets are selected, it returns an error. After generation, any set mutation (hex or binary) is applied to the output. Length specifies the pre-mutation length; the final length will differ if a mutation is applied. Returns an empty string and error if length <= 0 or no sets selected.

func (*StringBuilder) MustGenerate added in v0.7.0

func (sb *StringBuilder) MustGenerate(length int) string

MustGenerate creates a random string of the specified length using the configured character set. It panics if generation fails (e.g., length <= 0 or no character sets selected). This is a convenience method for cases where generation failure is considered a programming error.

func (*StringBuilder) WithLowerLetters added in v0.7.0

func (sb *StringBuilder) WithLowerLetters() *StringBuilder

WithLowerLetters adds lowercase letters (a-z) to the character set.

func (*StringBuilder) WithNumbers added in v0.7.0

func (sb *StringBuilder) WithNumbers() *StringBuilder

WithNumbers adds digits (0-9) to the character set.

func (*StringBuilder) WithSpecialCharacters added in v0.7.0

func (sb *StringBuilder) WithSpecialCharacters() *StringBuilder

WithSpecialCharacters adds special characters (!@#$%^&*()_+-=[]{}|;':",./<>?) to the character set.

func (*StringBuilder) WithUpperLetters added in v0.7.0

func (sb *StringBuilder) WithUpperLetters() *StringBuilder

WithUpperLetters adds uppercase letters (A-Z) to the character set.

type URLComparer added in v0.1.0

type URLComparer interface {
	// EqualStrings compares two URL strings after parsing and normalization.
	EqualStrings(a, b string) (bool, error)
	// EqualURLs compares two url.URL instances after normalization.
	EqualURLs(a, b *url.URL) bool
}

URLComparer defines methods to safely compare URL strings and url.URL instances.

func NewURLComparer added in v0.1.0

func NewURLComparer() URLComparer

NewURLComparer returns a new DefaultURLComparer.

Jump to

Keyboard shortcuts

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