env

package
v0.0.0-...-4fd6c8e Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package env makes it possible to track use of environment variables within a procress in order to generate documentation for these uses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterVar

func RegisterVar(v Var)

RegisterVar registers a generic environment variable.

Types

type BoolVar

type BoolVar struct {
	Var
}

BoolVar represents a single boolean environment variable.

func RegisterBoolVar

func RegisterBoolVar(name string, defaultValue bool, description string) BoolVar

RegisterBoolVar registers a new boolean environment variable.

func (BoolVar) Get

func (v BoolVar) Get() bool

Get retrieves the value of the environment variable. It returns the value, which will be the default if the variable is not present. To distinguish between an empty value and an unset value, use Lookup.

func (BoolVar) Lookup

func (v BoolVar) Lookup() (bool, bool)

Lookup retrieves the value of the environment variable. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be the default and the boolean will be false.

type DurationVar

type DurationVar struct {
	Var
}

DurationVar represents a single duration environment variable.

func RegisterDurationVar

func RegisterDurationVar(name string, defaultValue time.Duration, description string) DurationVar

RegisterDurationVar registers a new duration environment variable.

func (DurationVar) Get

func (v DurationVar) Get() time.Duration

Get retrieves the value of the environment variable. It returns the value, which will be the default if the variable is not present. To distinguish between an empty value and an unset value, use Lookup.

func (DurationVar) Lookup

func (v DurationVar) Lookup() (time.Duration, bool)

Lookup retrieves the value of the environment variable. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be the default and the boolean will be false.

type FloatVar

type FloatVar struct {
	Var
}

FloatVar represents a single floating-point environment variable.

func RegisterFloatVar

func RegisterFloatVar(name string, defaultValue float64, description string) FloatVar

RegisterFloatVar registers a new floating-point environment variable.

func (FloatVar) Get

func (v FloatVar) Get() float64

Get retrieves the value of the environment variable. It returns the value, which will be the default if the variable is not present. To distinguish between an empty value and an unset value, use Lookup.

func (FloatVar) Lookup

func (v FloatVar) Lookup() (float64, bool)

Lookup retrieves the value of the environment variable. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be the default and the boolean will be false.

type GenericVar

type GenericVar[T Parseable] struct {
	Var
	// contains filtered or unexported fields
}

func Register

func Register[T Parseable](name string, defaultValue T, description string) GenericVar[T]

func (GenericVar[T]) Get

func (v GenericVar[T]) Get() T

Get retrieves the value of the environment variable. It returns the value, which will be the default if the variable is not present. To distinguish between an empty value and an unset value, use Lookup.

func (GenericVar[T]) GetName

func (v GenericVar[T]) GetName() string

func (GenericVar[T]) IsSet

func (v GenericVar[T]) IsSet() bool

func (GenericVar[T]) Lookup

func (v GenericVar[T]) Lookup() (T, bool)

Lookup retrieves the value of the environment variable. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be the default and the boolean will be false.

type IntVar

type IntVar struct {
	Var
}

IntVar represents a single integer environment variable.

func RegisterIntVar

func RegisterIntVar(name string, defaultValue int, description string) IntVar

RegisterIntVar registers a new integer environment variable.

func (IntVar) Get

func (v IntVar) Get() int

Get retrieves the value of the environment variable. It returns the value, which will be the default if the variable is not present. To distinguish between an empty value and an unset value, use Lookup.

func (IntVar) Lookup

func (v IntVar) Lookup() (int, bool)

Lookup retrieves the value of the environment variable. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be the default and the boolean will be false.

type Parseable

type Parseable interface {
	comparable
}

type StringVar

type StringVar struct {
	Var
}

StringVar represents a single string environment variable.

func RegisterStringVar

func RegisterStringVar(name string, defaultValue string, description string) StringVar

RegisterStringVar registers a new string environment variable.

func (StringVar) Get

func (v StringVar) Get() string

Get retrieves the value of the environment variable. It returns the value, which will be the default if the variable is not present. To distinguish between an empty value and an unset value, use Lookup.

func (StringVar) Lookup

func (v StringVar) Lookup() (string, bool)

Lookup retrieves the value of the environment variable. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be the default and the boolean will be false.

type Var

type Var struct {
	// The name of the environment variable.
	Name string

	// The optional default value of the environment variable.
	DefaultValue string

	// Description of the environment variable's purpose.
	Description string

	// Hide the existence of this variable when outputting usage information.
	Hidden bool

	// Mark this variable as deprecated when generating usage information.
	Deprecated bool

	// The type of the variable's value
	Type VarType

	// The underlying Go type of the variable
	GoType string
}

Var describes a single environment variable

func VarDescriptions

func VarDescriptions() []Var

VarDescriptions returns a description of this process' environment variables, sorted by name.

type VarType

type VarType byte

The type of a variable's value

const (
	// Variable holds a free-form string.
	STRING VarType = iota
	// Variable holds a boolean value.
	BOOL
	// Variable holds a signed integer.
	INT
	// Variables holds a floating point value.
	FLOAT
	// Variable holds a time duration.
	DURATION
	// Variable holds a dynamic unknown type.
	OTHER
)

type VariableInfo

type VariableInfo interface {
	GetName() string
	IsSet() bool
}

VariableInfo provides generic information about a variable. All Variables implement this interface. This is largely to workaround lack of covariance in Go.

Jump to

Keyboard shortcuts

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