util

package
v0.0.0-...-540bb61 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const TimeLayout = time.RFC3339

Variables

This section is empty.

Functions

func BoolSwitch

func BoolSwitch[T interface{}](s bool, t, f T) T

BoolSwitch define bool switch for defined types - in case of true t T is returned, in case of false f T

func CompareInt

func CompareInt(a, b int) bool

func CompareInt64

func CompareInt64(a, b int64) bool

func CompareInt64p

func CompareInt64p(a, b *int64) bool

func CompareIntp

func CompareIntp(a, b *int) bool

func CompareJSON

func CompareJSON(a, b interface{}) (bool, error)

func CreateSignalContext

func CreateSignalContext(ctx context.Context) context.Context

CreateSignalContext creates and returns the context which is closed when one of the provided signal occurs. SIGINT and SIGTERM is used by default.

func NewType

func NewType[T interface{}](input T) *T

NewType returns a reference to a simple type with given value.

func NewTypeOrNil

func NewTypeOrNil[T interface{}](input *T) *T

NewTypeOrNil returns nil if input is nil, otherwise returns a clone of the given value.

func NormalizeEnv

func NormalizeEnv(env string) string

NormalizeEnv normalizes environment variables.

func ParallelThread

func ParallelThread(max int) (chan struct{}, func())

func ParseAgencyTime

func ParseAgencyTime(s string) (time.Time, bool)

func ParseTime

func ParseTime(s string, layouts ...string) (time.Time, int)

func RunParallel

func RunParallel(max int, actions ...func() error) error

RunParallel runs actions parallelly throttling them to the given maximum number.

func SHA256

func SHA256(data []byte) string

func SHA256FromJSON

func SHA256FromJSON(a interface{}) (string, error)

func SHA256FromString

func SHA256FromString(data string) string

func SortKeys

func SortKeys(m interface{}) []string

func TimeAgencyLayouts

func TimeAgencyLayouts() []string

func TimeCompareEqual

func TimeCompareEqual(a, b meta.Time) bool

TimeCompareEqual compares two times, allowing an error of 1s

func TimeCompareEqualPointer

func TimeCompareEqualPointer(a, b *meta.Time) bool

TimeCompareEqualPointer compares two times, allowing an error of 1s

func TypeOrDefault

func TypeOrDefault[T interface{}](input *T, defaultValue ...T) T

TypeOrDefault returns the default value (or T default value) if input is nil, otherwise returns the referenced value.

Types

type Close

type Close interface {
	Close() error
}

func CloseOnce

func CloseOnce(c Close) Close

type EnvironmentVariable

type EnvironmentVariable string

EnvironmentVariable is a wrapper to get environment variables

func (EnvironmentVariable) Exists

func (e EnvironmentVariable) Exists() bool

Exists check if variable is defined

func (EnvironmentVariable) Get

func (e EnvironmentVariable) Get() string

Get fetch variable. If variable does not exist empty string is returned

func (EnvironmentVariable) GetOrDefault

func (e EnvironmentVariable) GetOrDefault(d string) string

GetOrDefault fetch variable. If variable is not defined default value is returned

func (EnvironmentVariable) Lookup

func (e EnvironmentVariable) Lookup() (string, bool)

Lookup for environment variable

func (EnvironmentVariable) String

func (e EnvironmentVariable) String() string

String return string representation of environment variable name

type Interval

type Interval time.Duration

Interval is a specialization of Duration so we can add some helper functions to that.

func (Interval) After

func (i Interval) After() <-chan time.Time

After waits for the interval to elapse and then sends the current time on the returned channel.

func (Interval) Backoff

func (i Interval) Backoff(factor float64, maxInt Interval) Interval

Backoff returns an interval that is equal to min(i*factor, maxInt).

func (Interval) IncreaseTo

func (i Interval) IncreaseTo(x Interval) Interval

IncreaseTo returns an interval that is equal to max(x, i).

func (Interval) ReduceTo

func (i Interval) ReduceTo(x Interval) Interval

ReduceTo returns an interval that is equal to min(x, i).

func (Interval) String

func (i Interval) String() string

Jump to

Keyboard shortcuts

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