env: github.com/simia-tech/env Index | Files

package env

import "github.com/simia-tech/env"

Index

Package Files

bool.go bytes.go duration.go error.go field.go int.go ints.go options.go print.go print_flag.go string.go strings.go

Variables

var (
    NullErrorHandler   = func(error) {}
    StdoutErrorHandler = func(err error) {
        fmt.Fprintln(os.Stdout, err)
    }
    StderrErrorHandler = func(err error) {
        fmt.Fprintln(os.Stderr, err)
    }
    LogErrorHandler = func(err error) {
        log.Println(err)
    }
)

Implementations of different error handlers.

var ErrorHandler = StderrErrorHandler

ErrorHandler defines a handler for error messages. By default, LogErrorHandler is set.

func Clear Uses

func Clear()

Clear clears the field register.

func Fields Uses

func Fields() []string

Fields returns a slice of strings with all registered fields.

func ParseFlags Uses

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 Uses

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

Print prints the environment in the provided format.

type BoolField Uses

type BoolField struct {
    // contains filtered or unexported fields
}

BoolField implements a duration field.

func Bool Uses

func Bool(name string, defaultValue bool, opts ...Option) *BoolField

Bool registers a field of the provided name.

func (*BoolField) DefaultValue Uses

func (i *BoolField) DefaultValue() string

DefaultValue returns the field's default value.

func (*BoolField) Description Uses

func (i *BoolField) Description() string

Description returns the field's description.

func (*BoolField) Get Uses

func (i *BoolField) Get() bool

Get returns the field value or the default value.

func (BoolField) Name Uses

func (f BoolField) Name() string

func (*BoolField) Value Uses

func (i *BoolField) Value() string

Value returns the field's value.

type BytesField Uses

type BytesField struct {
    // contains filtered or unexported fields
}

BytesField implements a string field.

func Bytes Uses

func Bytes(name string, defaultValue []byte, opts ...Option) *BytesField

Bytes registers a field of the provided name.

func (*BytesField) DefaultValue Uses

func (bf *BytesField) DefaultValue() string

DefaultValue returns the field's default value.

func (*BytesField) Description Uses

func (bf *BytesField) Description() string

Description returns the field's description.

func (*BytesField) Get Uses

func (bf *BytesField) Get() []byte

Get returns the field value or the default value.

func (BytesField) Name Uses

func (f BytesField) Name() string

func (*BytesField) Value Uses

func (bf *BytesField) Value() string

Value returns the field's value.

type DurationField Uses

type DurationField struct {
    // contains filtered or unexported fields
}

DurationField implements a duration field.

func Duration Uses

func Duration(name string, defaultValue time.Duration, opts ...Option) *DurationField

Duration registers a field of the provided name.

func (*DurationField) DefaultValue Uses

func (df *DurationField) DefaultValue() string

DefaultValue returns the field's default value.

func (*DurationField) Description Uses

func (df *DurationField) Description() string

Description returns the field's description.

func (*DurationField) Get Uses

func (df *DurationField) Get() time.Duration

Get returns the field value or the default value.

func (DurationField) Name Uses

func (f DurationField) Name() string

func (*DurationField) Value Uses

func (df *DurationField) Value() string

Value returns the field's value.

type Field Uses

type Field interface {
    Name() string
    Value() string
    DefaultValue() string
    Description() string
}

Field implements an environment configuration field.

func RegisterField Uses

func RegisterField(field Field) Field

RegisterField adds the provided `Field` to the global field-register.

type IntField Uses

type IntField struct {
    // contains filtered or unexported fields
}

IntField implements a duration field.

func Int Uses

func Int(name string, defaultValue int, opts ...Option) *IntField

Int registers a field of the provided name.

func (*IntField) DefaultValue Uses

func (i *IntField) DefaultValue() string

DefaultValue returns the field's default value.

func (*IntField) Description Uses

func (i *IntField) Description() string

Description returns the field's description.

func (*IntField) Get Uses

func (i *IntField) Get() int

Get returns the field value or the default value.

func (IntField) Name Uses

func (f IntField) Name() string

func (*IntField) Value Uses

func (i *IntField) Value() string

Value returns the field's value.

type IntsField Uses

type IntsField struct {
    // contains filtered or unexported fields
}

IntsField implements a ints field.

func Ints Uses

func Ints(name string, defaultValue []int, opts ...Option) *IntsField

Ints registers a field of the provided name.

func (*IntsField) DefaultValue Uses

func (isf *IntsField) DefaultValue() string

DefaultValue returns the field's default value.

func (*IntsField) Description Uses

func (isf *IntsField) Description() string

Description returns the field's description.

func (*IntsField) Get Uses

func (isf *IntsField) Get() []int

Get returns the field value or the default value.

func (IntsField) Name Uses

func (f IntsField) Name() string

func (*IntsField) Value Uses

func (isf *IntsField) Value() string

Value returns the field's value.

type Option Uses

type Option func(*options)

Option defines an Option that can modify the options struct.

func AllowedValues Uses

func AllowedValues(values ...string) Option

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

func Description Uses

func Description(text string) Option

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

func Required Uses

func Required() Option

Required returns an Option that makes the environment field required.

type StringField Uses

type StringField struct {
    // contains filtered or unexported fields
}

StringField implements a string field.

func String Uses

func String(name, defaultValue string, opts ...Option) *StringField

String registers a field of the provided name.

func (*StringField) DefaultValue Uses

func (sf *StringField) DefaultValue() string

DefaultValue returns the field's default value.

func (*StringField) Description Uses

func (sf *StringField) Description() string

Description returns the field's description.

func (*StringField) Get Uses

func (sf *StringField) Get() string

Get returns the field value or the default value.

func (StringField) Name Uses

func (f StringField) Name() string

func (*StringField) Value Uses

func (sf *StringField) Value() string

Value returns the field's value.

type StringsField Uses

type StringsField struct {
    // contains filtered or unexported fields
}

StringsField implements a strings field.

func Strings Uses

func Strings(name string, defaultValue []string, opts ...Option) *StringsField

Strings registers a field of the provided name.

func (*StringsField) DefaultValue Uses

func (sf *StringsField) DefaultValue() string

DefaultValue returns the field's default value.

func (*StringsField) Description Uses

func (sf *StringsField) Description() string

Description returns the field's description.

func (*StringsField) Get Uses

func (sf *StringsField) Get() []string

Get returns the field value or the default value.

func (StringsField) Name Uses

func (f StringsField) Name() string

func (*StringsField) Value Uses

func (sf *StringsField) Value() string

Value returns the field's value.

Package env imports 12 packages (graph). Updated 2019-10-27. Refresh now. Tools for package owners.