env

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Settings

type Settings struct {
	// Environ is a slice of "key=value" pairs which defaults
	// to the returned value of os.Environ().
	// Element without a '=' sign are ignored.
	// All environment variable keys read are eventually
	// transformed using the KeyTransform method.
	// It defaults to the empty string.
	Environ []string
	// KeyPrefix is a prefix to add to all keys read from
	// the environment. It is usually the program name to avoid
	// conflict with other programs in the environment.
	// It defaults to the empty string.
	KeyPrefix string
}

Settings contains settings for the environment variable source.

type Source

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

Source implements an environment variables source. Note all keys are transformed using its KeyTransform method.

func New

func New(settings Settings) (source *Source)

New creates a new environment variable source given the environment as a slice of key-value pairs, which can generally be obtained with os.Environ(). Environ values with no '=' sign are ignored. All environment variable keys read are eventually transformed using the KeyTransform method.

func (*Source) Get

func (s *Source) Get(key string) (value string, isSet bool)

Get returns the value of the environment variable found at the given key, and a boolean `isSet` to indicate if it is set or not.

func (*Source) KeyTransform

func (s *Source) KeyTransform(key string) (newKey string)

KeyTransform transforms a generic key to an environment variable key. It notably: - Changes all characters to be uppercase - Replaces all dashes with underscores. - Prefixes the key with the KeyPrefix field, without modifying the prefix.

func (*Source) String

func (s *Source) String() string

Jump to

Keyboard shortcuts

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