utils

package
v3.0.0-rc.12 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 17 Imported by: 10

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultYeast = NewYeast()

Functions

func Base64Id

func Base64Id() *base64Id
Example
_, err := Base64Id().GenerateId()
fmt.Println(err)
Output:
<nil>

func CheckInvalidHeaderChar

func CheckInvalidHeaderChar(val string) bool

CheckInvalidHeaderChar reports whether v is an invalid "field-value" according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 :

message-header = field-name ":" [ field-value ]
field-value    = *( field-content | LWS )
field-content  = <the OCTETs making up the field-value
                 and consisting of either *TEXT or combinations
                 of token, separators, and quoted-string>

http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2 :

TEXT           = <any OCTET except CTLs,
                  but including LWS>
LWS            = [CRLF] 1*( SP | HT )
CTL            = <any US-ASCII control character
                 (octets 0 - 31) and DEL (127)>

RFC 7230 says:

field-value    = *( field-content / obs-fold )
obj-fold       =  N/A to http2, and deprecated
field-content  = field-vchar [ 1*( SP / HTAB ) field-vchar ]
field-vchar    = VCHAR / obs-text
obs-text       = %x80-FF
VCHAR          = "any visible [USASCII] character"

http2 further says: "Similarly, HTTP/2 allows header field values that are not valid. While most of the values that can be encoded will not alter header field parsing, carriage return (CR, ASCII 0xd), line feed (LF, ASCII 0xa), and the zero character (NUL, ASCII 0x0) might be exploited by an attacker if they are translated verbatim. Any request or response that contains a character not permitted in a header field value MUST be treated as malformed (Section 8.1.2.6). Valid characters are defined by the field-content ABNF rule in Section 3.2 of [RFC7230]."

This function does not (yet?) properly handle the rejection of strings that begin or end with SP or HTAB.

func CleanPath

func CleanPath(p string) string

func ClearInterval

func ClearInterval(timer *Timer)

func ClearTimeout

func ClearTimeout(timer *Timer)

func Contains

func Contains(haystack string, needles []string) string

func Is

func Is[T any](val any) bool

func Log

func Log() *log.Log

func MapValues

func MapValues[K comparable, I any, O any](input map[K]I, transform func(I) O) map[K]O

func MsgPack

func MsgPack() *msgPack

func NewUtf8Decoder

func NewUtf8Decoder(r io.Reader) io.Reader

func NewUtf8Encoder

func NewUtf8Encoder(w io.Writer) io.Writer

NewEncoder returns an io.Writer that writes lowercase hexadecimal characters to w.

func Ptr

func Ptr[T any](v T) *T

func StripHostPort

func StripHostPort(h string) string

func Tap

func Tap[T any](value T, callback func(T)) T

Tap calls the given function with the given value, then returns the value.

func TryCast

func TryCast[T any](val any) T

func Utf8decodeBytes

func Utf8decodeBytes(src []byte) []byte

func Utf8decodeString

func Utf8decodeString(byteString string) string

func Utf8encodeBytes

func Utf8encodeBytes(src []byte) []byte

func Utf8encodeString

func Utf8encodeString(src string) string

func Utf16Count

func Utf16Count(src []byte) (n int)

func Utf16CountString

func Utf16CountString(src string) (n int)

func Utf16Len

func Utf16Len(v rune) int

func Value

func Value(value string, _default string) string

func YeastDate

func YeastDate() string

Types

type Backoff

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

Backoff represents a thread-safe exponential backoff timer.

func NewBackoff

func NewBackoff(opts ...BackoffOption) *Backoff

NewBackoff creates a new Backoff instance with the given options.

func (*Backoff) Attempts

func (b *Backoff) Attempts() uint64

Attempts returns the current number of attempts.

func (*Backoff) Duration

func (b *Backoff) Duration() int64

Duration calculates and returns the next backoff duration in milliseconds.

func (*Backoff) GetFactor

func (b *Backoff) GetFactor() float64

GetFactor returns the current growth factor.

func (*Backoff) GetJitter

func (b *Backoff) GetJitter() float64

GetJitter returns the current jitter factor.

func (*Backoff) GetMax

func (b *Backoff) GetMax() float64

GetMax returns the current maximum backoff duration.

func (*Backoff) GetMin

func (b *Backoff) GetMin() float64

GetMin returns the current minimum backoff duration.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset resets the attempt counter to zero.

func (*Backoff) SetFactor

func (b *Backoff) SetFactor(val float64)

SetFactor sets the growth factor.

func (*Backoff) SetJitter

func (b *Backoff) SetJitter(val float64)

SetJitter sets the jitter factor.

func (*Backoff) SetMax

func (b *Backoff) SetMax(val float64)

SetMax sets the maximum backoff duration.

func (*Backoff) SetMin

func (b *Backoff) SetMin(val float64)

SetMin sets the minimum backoff duration.

type BackoffOption

type BackoffOption func(*Backoff)

BackoffOption defines a configuration option function type.

func WithFactor

func WithFactor(factor float64) BackoffOption

WithFactor sets the exponential growth factor.

func WithJitter

func WithJitter(jitter float64) BackoffOption

WithJitter sets the jitter factor (between 0 and 1).

func WithMax

func WithMax(max float64) BackoffOption

WithMax sets the maximum backoff duration in milliseconds.

func WithMin

func WithMin(min float64) BackoffOption

WithMin sets the minimum backoff duration in milliseconds.

type ParsedUrl

type ParsedUrl struct {
	*url.URL

	Hostname string
	Port     string
	Id       string
}

func Url

func Url(uri string, path string) (parsedUrl *ParsedUrl, err error)

type Timer

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

func SetInterval

func SetInterval(fn func(), sleep time.Duration) *Timer

func SetTimeout

func SetTimeout(fn func(), sleep time.Duration) *Timer

func (*Timer) Refresh

func (t *Timer) Refresh() *Timer

func (*Timer) Stop

func (t *Timer) Stop()

func (*Timer) Unref

func (t *Timer) Unref()

type Yeast

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

func NewYeast

func NewYeast() *Yeast

func (*Yeast) Decode

func (y *Yeast) Decode(str string) int64

func (*Yeast) Encode

func (y *Yeast) Encode(num int64) (encoded string)

func (*Yeast) Yeast

func (y *Yeast) Yeast() string

Jump to

Keyboard shortcuts

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