env

package module
v0.0.0-...-14518b3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: Unlicense Imports: 14 Imported by: 0

README

YAGCL env

Go Reference Build and Tests codecov

This package provides a YAGCL source that provides access to reading environment variables.

Usage

go get github.com/Bios-Marcel/yagcl-env

Reporting Issues / Requesting features

All "official" sources for YAGCL should be reported in the main repositories issue section.

Syntax

Reserved characters

Reserved characters have a concrete meaning for certain value types. Each value type can have different reserved characters. Check the documentation for the corresponding type in order to see them.

Each reserved character can be escaped via \. If you need a literal \, write \\ instead.

Arrays / Slices

These types support lists of 0 to N elements. If you have a fixed size array, you'll need to supply an exact amount of elements.

The elements can be of any type, as long as the type is parsable.

If your type is []string, the elements will be conveterted into string, if you have an []int, you'll have to pass only valid int values. Values are separated by single commas.

For example, if given:

VAR_NAME=word,12,Hello\, Chris

You would get:

["word","12","Hello, Christ"]

Reserved characters:

  • ,
Maps

This type allows you to do a KEY=VALUE mapping, where you can have more than one key-value pair.

The pairs are separated by single commas. The key and the value are separated by an equal sign.

For example, if given:

VAR_NAME=a=1,b=2,weird\=key=3

You would get:

{
    "a": 1,
    "b": 2,
    "weird=key": 3,
}

Reserved characters:

  • ,
  • =

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMultipleDataSourcesSpecified = errors.New("more than one data source specified; only call one of Bytes(), String(), Reader() or Path()")

ErrNoDataSourceSpecified is thrown if more than one of Bytes, String, Path or Reader of the EnvSourceSetupStepOne interface have been called.

View Source
var ErrNoDataSourceSpecified = errors.New("no data source specified; call Bytes(), String(), Reader() or Path()")

ErrNoDataSourceSpecified is thrown if none Bytes, String, Path or Reader of the EnvSourceSetupStepOne interface have been called.

Functions

This section is empty.

Types

type EnvSourceOptionalSetup

type EnvSourceOptionalSetup[T yagcl.Source] interface {
	yagcl.Source

	// Prefix specified the prefixes expected in environment variable keys.
	// For example "PREFIX_FIELD_NAME".
	Prefix(string) T
	// KeyValueConverter defines how the yagcl.DefaultKeyTagName value should be
	// converted for this source. If you are setting this, you'll most likely
	// also have to set EnvSource.KeyJoiner(string,string) string.
	// Note that calling this isn't required, as there's a best practise default
	// behaviour.
	KeyValueConverter(func(string) string) T
	// KeyJoiner defines the function that builds the environment variable keys.
	// For example consider the following struct:
	//
	//	type Config struct {
	//	    Sub struct {
	//	        Field int `key:"field"`
	//	    } `key:"sub"`
	//	}
	//
	// The joiner could for example produce sub_field, depending. In combination
	// with KeyValueConverter, this could then become SUB_FIELD.
	KeyJoiner(func(string, string) string) T
}

type EnvSourceSetupStepOne

type EnvSourceSetupStepOne[T yagcl.Source] interface {
	// Bytes defines a byte array to read from directly.
	Bytes([]byte) EnvSourceSetupStepTwoEnvFile[T]
	// Bytes defines a string to read from directly.
	String(string) EnvSourceSetupStepTwoEnvFile[T]
	// Path defines a filepath that is accessed when YAGCL.Parse is called.
	Path(string) EnvSourceSetupStepTwoEnvFile[T]
	// Reader defines a reader that is accessed when YAGCL.Parse is called. IF
	// available, io.Closer.Close() is called.
	Reader(io.Reader) EnvSourceSetupStepTwoEnvFile[T]
	// Env instructs the source to read directly from the environment
	// variables.
	Env() EnvSourceSetupStepTwoEnv[T]
}

func Source

func Source() EnvSourceSetupStepOne[*envSourceImpl]

Source creates a source for environment variables of the current process.

type EnvSourceSetupStepTwoEnv

type EnvSourceSetupStepTwoEnv[T yagcl.Source] interface {
	EnvSourceOptionalSetup[T]
}

type EnvSourceSetupStepTwoEnvFile

type EnvSourceSetupStepTwoEnvFile[T yagcl.Source] interface {
	EnvSourceOptionalSetup[T]

	// LoadIntoEnv activates loading the unparsed data into the environment
	// variables of the process.
	LoadIntoEnv() T
	// Must declares this source as mandatory, erroring in case no data can
	// be loaded. In case of loading directly from the environment, this
	// will always succeed though, as the environment is always there, even
	// if we can't load any values, due to the fact they aren't available.
	Must() T
}

Jump to

Keyboard shortcuts

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