Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Or ¶
func Or[T Constraint](vars ...Var[T]) T
Or returns the first of its arguments for which Var.TryGet returns ok == true. If no argument is suitable, it returns the zero value.
func SetDefault ¶
func SetDefault[T Constraint](v Var[T], value T)
SetDefault sets default value for the given var.
This function is safe to call from multiple goroutines.
Types ¶
type Constraint ¶
type Constraint interface {
int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64
}
Constraint defines all supported types for Var.
It does not permit ~T (tilde) types since other types may be parsed differently, which may result unexpected behavior.
type Var ¶
type Var[T Constraint] string
Var is an environment variable.
T defines which value type this is expected by this variable.
func (Var[T]) Get ¶
func (v Var[T]) Get() T
Get returns the value of this variable. It value is missing or not scannable by fmt.Sscanf it returns default value.
See also SetDefault to set a default value.
func (Var[T]) GetOr ¶
func (v Var[T]) GetOr(or ...T) T
GetOr returns the first of its arguments that is not equal to the zero value. If no argument is non-zero, it returns the zero value.
func (Var[T]) TryGet ¶
TryGet returns a value of this variable and boolean stating whether value was present and fmt.Sscanf successfully scanned it.