env

package module
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingValue = errors.New("missing value")
	ErrInvalidValue = errors.New("invalid value")
)

Functions

func ClearRegister

func ClearRegister()

func ParseFlags

func ParseFlags()

ParseFlags tests if the print-flag was given at the program start and prints the registered environment fields with thier values to stdout using the specified format. Afterwards, the program exits with return code 2.

func Print

func Print(w io.Writer, format string) error

Print prints the environment in the provided format.

func WithFlags

func WithFlags(fn func())

Types

type F added in v3.1.0

type F[T FieldType] struct {
	// contains filtered or unexported fields
}

func Field

func Field[T FieldType](name string, defaultValue T, opts ...Option) *F[T]

func (*F[T]) Description added in v3.1.0

func (f *F[T]) Description() string

func (*F[T]) Get added in v3.1.0

func (f *F[T]) Get() (T, error)

func (*F[T]) GetOrDefault added in v3.1.0

func (f *F[T]) GetOrDefault() T

func (*F[T]) GetRaw added in v3.1.0

func (f *F[T]) GetRaw() (string, error)

func (*F[T]) GetRawOrDefault added in v3.1.0

func (f *F[T]) GetRawOrDefault() string

func (*F[T]) MustGet added in v3.1.0

func (f *F[T]) MustGet() T

func (*F[T]) MustGetRaw added in v3.1.0

func (f *F[T]) MustGetRaw() string

func (*F[T]) Name added in v3.1.0

func (f *F[T]) Name() string

type FieldType

type FieldType interface {
	bool | []byte | time.Duration | int | string | []string | map[string]string
}

type Option

type Option func(*options)

Option defines an Option that can modify the options struct.

func AllowedValues

func AllowedValues(values ...string) Option

AllowedValues returns an Option that defines all allowed values for the environment field.

func Description

func Description(text string) Option

Description returns an Option that sets the description of the environment field.

func Required

func Required() Option

Required returns an Option that makes the environment field required.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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