util

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetTotalMemory = sync.OnceValue(func() int64 {
	v, e := mem.VirtualMemory()
	if e != nil {

		return 16 * 1024 * 1024 * 1024
	}
	return int64(v.Available)
})

Functions

func DrainClose

func DrainClose(r io.ReadCloser)

always closed: 20k -> 8 seconds never closed: 20k -> 200ms assuming we lose ~1s per connection and 10k clients we should close any given reader after 5s of stalling for normal-exit

func UnsafeBuffer

func UnsafeBuffer(s string) []byte

func UnsafeString

func UnsafeString(b []byte) string

Types

type Duration

type Duration time.Duration

func NewDuration

func NewDuration(d any) Duration

func (Duration) After

func (d Duration) 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 (Duration) AfterIf

func (d Duration) 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 (Duration) Clamp

func (d Duration) Clamp(lmin time.Duration, lmax time.Duration) Duration

Clamps the duration to the given range.

func (Duration) Display

func (d Duration) Display() string

func (Duration) Duration

func (d Duration) Duration() time.Duration

func (Duration) IsPositive

func (d Duration) IsPositive() bool

func (Duration) IsZero

func (d Duration) IsZero() bool

func (Duration) MarshalJSON

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

func (Duration) MarshalText

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

func (Duration) MarshalYAML

func (d Duration) MarshalYAML() (any, error)

func (Duration) Max

func (d Duration) Max(o time.Duration) Duration

func (Duration) Min

func (d Duration) Min(o time.Duration) Duration

func (Duration) Or

func (d Duration) Or(o time.Duration) Duration

func (Duration) String

func (d Duration) String() string

String representation of the duration.

func (Duration) Timeout

func (Duration) TimeoutCause

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

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

func (*Duration) UnmarshalJSON

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

func (*Duration) UnmarshalText

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

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(node *yaml.Node) error

type Enum

type Enum[T comparable] struct {
	Names  map[T]string
	Values map[string]T
	// contains filtered or unexported fields
}

func NewEnum

func NewEnum[T comparable](names map[T]string) Enum[T]

func (Enum[T]) MarshalText

func (e Enum[T]) MarshalText(value T) (text []byte, err error)

func (Enum[T]) ToString

func (e Enum[T]) ToString(value T) string

func (Enum[T]) ToValue

func (e Enum[T]) ToValue(name string) (T, bool)

func (Enum[T]) UnmarshalText

func (e Enum[T]) UnmarshalText(into *T, text []byte) error

type OrderedMap added in v0.2.7

type OrderedMap[K comparable, V any] []lo.Tuple2[K, V]

func (OrderedMap[K, V]) ForEach added in v0.2.7

func (m OrderedMap[K, V]) ForEach(fn func(k K, v V))

func (OrderedMap[K, V]) Get added in v0.2.7

func (m OrderedMap[K, V]) Get(key K) (v V, ok bool)

func (OrderedMap[K, V]) MarshalYAML added in v0.2.7

func (m OrderedMap[K, V]) MarshalYAML() (any, error)

func (*OrderedMap[K, V]) Set added in v0.2.7

func (m *OrderedMap[K, V]) Set(key K, value V)

func (*OrderedMap[K, V]) UnmarshalYAML added in v0.2.7

func (m *OrderedMap[K, V]) UnmarshalYAML(node *yaml.Node) error

type Size

type Size int

func NewSize

func NewSize(d any) Size

func (Size) Bytes

func (d Size) Bytes() int

func (Size) Display

func (n Size) Display() string

func (Size) Gigabytes

func (d Size) Gigabytes() int

func (Size) IsPositive

func (d Size) IsPositive() bool

func (Size) IsZero

func (d Size) IsZero() bool

func (Size) Kilobytes

func (d Size) Kilobytes() int

func (Size) MarshalJSON

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

func (Size) MarshalText

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

func (Size) Megabytes

func (d Size) Megabytes() int

func (Size) String

func (d Size) String() string

func (*Size) UnmarshalJSON

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

func (*Size) UnmarshalText

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

type Some

type Some[T any] []T

func Many

func Many[T any](a ...T) Some[T]

func One

func One[T any](a T) Some[T]

func (Some[T]) Elements

func (a Some[T]) Elements() []T

func (Some[T]) Filter

func (a Some[T]) Filter(f func(*T) bool) []T

func (Some[T]) ForEach

func (a Some[T]) ForEach(f func(*T))

func (Some[T]) IsZero

func (a Some[T]) IsZero() bool

func (Some[T]) MarshalJSON

func (a Some[T]) MarshalJSON() ([]byte, error)

func (Some[T]) MarshalYAML

func (a Some[T]) MarshalYAML() (any, error)

func (*Some[T]) String

func (a *Some[T]) String() string

func (*Some[T]) UnmarshalJSON

func (a *Some[T]) UnmarshalJSON(data []byte) error

func (*Some[T]) UnmarshalYAML

func (a *Some[T]) UnmarshalYAML(node *yaml.Node) error

type TimedMutex

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

func (*TimedMutex) Lock

func (tm *TimedMutex) Lock()

func (*TimedMutex) TryLock

func (tm *TimedMutex) TryLock(d time.Duration) bool

func (*TimedMutex) TryLockContext

func (tm *TimedMutex) TryLockContext(ctx context.Context) bool

func (*TimedMutex) Unlock

func (tm *TimedMutex) Unlock()

Jump to

Keyboard shortcuts

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