utils

package
v0.0.0-...-60828a5 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Must

func Must[T any](obj T, err error) T

func OptionalEnv

func OptionalEnv(key string, envUsageMsg string) (string, bool)

OptionalEnv returns the value of the environment variable for key if it is set, non-empty and not only whitespace.

Pass the envUsageMsg to describe what the environment variable is used for. This will be used in the message that is printed if the environment variable is not returned.

func RequiredEnv

func RequiredEnv(key string, envUsageMsg string) string

RequiredEnv returns the value of the environment variable for key if it is set, non-empty and not only whitespace. It panics otherwise.

Pass the envUsageMsg to describe what the environment variable is used for. This will be used in the error message.

Types

type LockableCancelableContext

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

func NewLockableCancelableContext

func NewLockableCancelableContext(ctx context.Context) *LockableCancelableContext

func (*LockableCancelableContext) Cancel

func (lcc *LockableCancelableContext) Cancel()

func (*LockableCancelableContext) Deadline

func (lcc *LockableCancelableContext) Deadline() (deadline time.Time, ok bool)

func (*LockableCancelableContext) Done

func (lcc *LockableCancelableContext) Done() <-chan struct{}

func (*LockableCancelableContext) Err

func (lcc *LockableCancelableContext) Err() error

func (*LockableCancelableContext) Lock

func (lcc *LockableCancelableContext) Lock()

func (*LockableCancelableContext) Unlock

func (lcc *LockableCancelableContext) Unlock()

func (*LockableCancelableContext) Value

func (lcc *LockableCancelableContext) Value(key interface{}) interface{}

type SetOnce

type SetOnce[T any] struct {
	// contains filtered or unexported fields
}

func NewSetOnce

func NewSetOnce[T any]() *SetOnce[T]

func (*SetOnce[T]) SetError

func (s *SetOnce[T]) SetError(err error) error

func (*SetOnce[T]) SetValue

func (s *SetOnce[T]) SetValue(value T) error

func (*SetOnce[T]) Wait

func (s *SetOnce[T]) Wait() (T, error)

Wait returns the value or error set by SetValue or SetError. It can be called multiple times, returning the same value or error.

func (*SetOnce[T]) WaitWithContext

func (s *SetOnce[T]) WaitWithContext(ctx context.Context) (T, error)

WaitWithContext TODO: Use waitWithContext in all places instead of Wait.

type WaitMap

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

WaitMap allows you to wait for functions with given keys and execute them only once.

func NewWaitMap

func NewWaitMap() *WaitMap

func (*WaitMap) Wait

func (m *WaitMap) Wait(key int64, fn func() error) error

Wait waits for the function with the given key to be executed. If the function is already executing, it waits for it to finish. If the function is not yet executing, it executes the function and returns its result.

Jump to

Keyboard shortcuts

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