env

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: BSD-3-Clause Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(environment Environment, schema Schema) error

Parse uses the given Schema to parse the environment variables in the given Environment. If the values of environment variables in Environment do not match the schema, or required variables are missing, an error is returned.

func ParseOS

func ParseOS(schema Schema) error

ParseOS is a convenience function for parsing the given Schema of environment variables using the environment variables accessed by the standard libraray os package. If the values of environment variables do not match the schema, or required variables are missing, an error is returned.

Types

type Environment

type Environment interface {
	Getenv(string) string
}

Environment is something that implements Getenv().

Most use cases can simply make use of the OS implementation which is backed by the standard library os package.

var OS Environment = new(osEnv)

OS is an implementation of Environment that uses the standard library os package to retrieve actual environment variables.

func File added in v0.3.3

func File(filename string) Environment

File is an implementation of Environment that reads environment variables from a file.

e.g. /etc/os-release

type Parser

type Parser interface {
	Parse(string) error
}

The Parser interface is what must be implemented to support decoding an environment variable into a custom type.

func Bool

func Bool(b *bool, required bool) Parser

Bool is used to extract an environment variable into a Go bool. If required is true, then an error is returned if the environment variable is not set or is empty.

func BoolOr added in v0.3.2

func BoolOr(b *bool, alt bool) Parser

BoolOr is used to extract an environment variable into a Go bool. If the environment variable is not set or is empty, then the alt value is used instead.

func Float

func Float(f *float64, required bool) Parser

Float is used to extract an environment variable into a Go float64. If required is true, then an error is returned if the environment variable is not set or is empty.

func FloatOr added in v0.3.2

func FloatOr(f *float64, alt float64) Parser

FloatOr is used to extract an environment variable into a Go float64. If the environment variable is not set or is emty, then the alt value is used instead.

func Int

func Int(i *int, required bool) Parser

Int is used to extract an environment variable into a Go int. If required is true, then an error is returned if the environment variable is not set or is empty.

func IntOr added in v0.3.2

func IntOr(i *int, alt int) Parser

IntOr is used to extract an environment variable into a Go int. If the environment variable is not set or is empty, then the alt value is used instead.

func Secret added in v0.3.1

func Secret(s **conceal.Text, required bool) Parser

Secret is used to extract an environment variable into a Go concel.Text object. If required is true, then an error is returned if the environment variable is not set or is empty.

func String

func String(s *string, required bool) Parser

String is used to extract an environment variable into a Go string. If required is true, then an error is returned if the environment variable is not set or is empty.

func StringOr added in v0.3.2

func StringOr(s *string, alt string) Parser

StringOr is used to extract an environment variable into a Go string. If the environment variable is not set or is empty, then the alt value is used instead.

type Schema

type Schema map[Variable]Parser

Schema is used to describe how to parse a set of environment variables.

type Variable

type Variable string

A Variable represents an environment variable.

func (Variable) Name

func (v Variable) Name() string

func (Variable) String

func (v Variable) String() string

Jump to

Keyboard shortcuts

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