util

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOk = fmt.Errorf("done")
View Source
var RunesAlpha = NewRuneSet(RunesLower.String(), RunesUpper.String())
View Source
var RunesAlphanum = NewRuneSet(RunesAlpha.String(), RunesNumeric.String())
View Source
var RunesLower = NewRuneSet("abcdefghijklmnopqrstuvwxyz")
View Source
var RunesNumeric = NewRuneSet("0123456789")
View Source
var RunesUpper = NewRuneSet("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

Functions

func Cause

func Cause(c context.Context) (err error)

func NotOk

func NotOk(e error) error

func OrOk

func OrOk(e error) error

func RandomBytes

func RandomBytes(n int) []byte

Types

type ParsableDuration

type ParsableDuration struct {
	time.Duration
}

func Duration

func Duration(d any) ParsableDuration

func (ParsableDuration) After

func (d ParsableDuration) After() <-chan time.Time

If positive duration, returns a channel that will be given the current time after the duration has passed. If non-positive duration, returns a closed channel, which will be selected immediately.

func (ParsableDuration) AfterIf

func (d ParsableDuration) AfterIf() <-chan time.Time

If positive duration, returns a channel that will be given the current time after the duration has passed. If non-positive duration, returns nil, which will never be selected.

func (ParsableDuration) Clamp

Clamps the duration to the given range.

func (ParsableDuration) IsPositive

func (d ParsableDuration) IsPositive() bool

func (ParsableDuration) IsZero

func (d ParsableDuration) IsZero() bool

func (ParsableDuration) MarshalJSON

func (d ParsableDuration) MarshalJSON() ([]byte, error)

func (ParsableDuration) MarshalText

func (d ParsableDuration) MarshalText() ([]byte, error)

func (ParsableDuration) Max

func (ParsableDuration) Min

func (ParsableDuration) String

func (d ParsableDuration) String() string

String representation of the duration.

func (ParsableDuration) Timeout

func (ParsableDuration) TimeoutCause

func (d ParsableDuration) TimeoutCause(ctx context.Context, cause error) (context.Context, context.CancelFunc)

Creates a context that will be cancelled after the duration has passed.

func (*ParsableDuration) UnmarshalJSON

func (d *ParsableDuration) UnmarshalJSON(text []byte) (err error)

func (*ParsableDuration) UnmarshalText

func (d *ParsableDuration) UnmarshalText(text []byte) (err error)

type ParsableSize

type ParsableSize struct {
	Value int
}

func Bytesize

func Bytesize(d any) ParsableSize

func (ParsableSize) IsPositive

func (d ParsableSize) IsPositive() bool

func (ParsableSize) IsZero

func (d ParsableSize) IsZero() bool

func (ParsableSize) MarshalJSON

func (d ParsableSize) MarshalJSON() ([]byte, error)

func (ParsableSize) MarshalText

func (d ParsableSize) MarshalText() ([]byte, error)

func (ParsableSize) String

func (d ParsableSize) String() string

func (*ParsableSize) UnmarshalJSON

func (d *ParsableSize) UnmarshalJSON(text []byte) (err error)

func (*ParsableSize) UnmarshalText

func (d *ParsableSize) UnmarshalText(text []byte) (err error)

type RuneSet

type RuneSet map[rune]struct{}

func NewRuneSet

func NewRuneSet(strings ...string) RuneSet

func (RuneSet) Add

func (d RuneSet) Add(s string)

func (RuneSet) AddRune

func (d RuneSet) AddRune(r rune)

func (RuneSet) Remove

func (d RuneSet) Remove(s string)

func (RuneSet) RemoveRune

func (d RuneSet) RemoveRune(r rune)

func (RuneSet) String

func (d RuneSet) String() string

func (RuneSet) Test

func (d RuneSet) Test(s string) bool

func (RuneSet) TestRune

func (d RuneSet) TestRune(r rune) (ok bool)

type TimerRate

type TimerRate struct {
	Count  uint32
	Period time.Duration
}

func Rate

func Rate(v ...any) TimerRate

func (TimerRate) Clamp

func (d TimerRate) Clamp(rateMin TimerRate, rateMax TimerRate) TimerRate

func (TimerRate) ClampPeriod

func (d TimerRate) ClampPeriod(pmin time.Duration, pmax time.Duration) TimerRate

func (TimerRate) Compare

func (d TimerRate) Compare(o TimerRate) int

func (TimerRate) Faster

func (d TimerRate) Faster(o TimerRate) bool

func (TimerRate) IsPositive

func (d TimerRate) IsPositive() bool

func (TimerRate) IsZero

func (d TimerRate) IsZero() bool

func (TimerRate) MarshalText

func (d TimerRate) MarshalText() ([]byte, error)

func (TimerRate) Rescale

func (d TimerRate) Rescale(period time.Duration) TimerRate

func (TimerRate) Slower

func (d TimerRate) Slower(o TimerRate) bool

func (TimerRate) String

func (d TimerRate) String() string

func (TimerRate) Ticks

func (d TimerRate) Ticks() uint32

func (TimerRate) ToTicks

func (d TimerRate) ToTicks(t time.Time) uint32

func (*TimerRate) UnmarshalText

func (d *TimerRate) UnmarshalText(text []byte) (err error)

Jump to

Keyboard shortcuts

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