values

package
v0.4.39 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 9 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v any) bool

Bool returns bool value

func Coalesce

func Coalesce[M Measurable[any]](args ...M) M

Coalesce returns the first non-empty value

func Int

func Int(v any) int

Int will return the value as int

func Int64

func Int64(v any) int64

Int64 will return the value as int64

func IsCollection

func IsCollection(value any) bool

IsCollection returns true for slices and maps

func JSON added in v0.4.1

func JSON(value any) string

JSON returns the value as a JSON string

func NumbersCoalesce

func NumbersCoalesce[T ~int | ~int32 | ~uint | ~uint32 | ~int64 | ~uint64](items ...T) T

NumbersCoalesce returns the first value from the supplied list that is not 0, or 0 if there are no values that are not zero

func Select

func Select[T any](cond bool, a, b T) T

Select returns a if cond is true, otherwise b

func String

func String(v any) string

String returns string value

func StringSlice

func StringSlice(v any) []string

StringSlice returns slice of string values

func StringsCoalesce

func StringsCoalesce(str ...string) string

StringsCoalesce returns the first non-empty string value

func Time

func Time(v any) *time.Time

Time will return the value as Time

func UInt64

func UInt64(v any) uint64

UInt64 will return the value as uint64

Types

type MapAny

type MapAny map[string]any

MapAny provides map of values

func FromJSON

func FromJSON(s string) MapAny

FromJSON returns map from json encoded string, this method does not return value on error, as the value is expected a valid JSON string.

func FromYAML

func FromYAML(s string) MapAny

FromYAML returns map from yaml encoded string, this method does not return value on error, as the value is expected a valid YAML string.

func (MapAny) Bool

func (c MapAny) Bool(k string) bool

Bool will return the value as Bool

func (MapAny) GetOrSet added in v0.4.1

func (c MapAny) GetOrSet(key string, getter func(key string) any) any

GetOrSet existing existing value or set new value

func (MapAny) Int

func (c MapAny) Int(k string) int

Int will return the value as an int

func (MapAny) Int64

func (c MapAny) Int64(k string) int64

Int64 will return the named value as an int64

func (MapAny) JSON

func (c MapAny) JSON() string

JSON returns JSON encoded string

func (MapAny) String

func (c MapAny) String(k string) string

String will return the value as a string, if the underlying type is not a string, it will try and co-oerce it to a string.

func (MapAny) StringSlice

func (c MapAny) StringSlice(k string) []string

StringSlice returns slice of string values

func (MapAny) Time

func (c MapAny) Time(k string) *time.Time

Time will return the value as Time

func (MapAny) To

func (c MapAny) To(val any) error

To converts the values to the value pointed to by val.

func (MapAny) UInt64

func (c MapAny) UInt64(k string) uint64

UInt64 will return the named value as an uint64

func (MapAny) YAML

func (c MapAny) YAML() string

YAML returns YAML encoded string

type Measurable

type Measurable[T any] interface {
	~string | ~[]string | ~[]T
}

Measurable interface

Jump to

Keyboard shortcuts

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