Documentation
¶
Overview ¶
Package starenv implements populating environmental variables from variety of sources.
Usage ¶
Simplest way to use starenv is to import the autoload package:
import _ "github.com/oxplot/starenv/autoload"
The above will iterate through all environmental variables looking for specially formatted values which tell it where to load the final values from. After the above is imported, you can use the usual os.Getenv() to get the value of environmental variables.
Ref Pipline ¶
The source of a value is defined as a pipeline of "derefer" tags followed by the reference for the last derefer. Here is an example of a environmental variable specifying to load its value from a base64 encoded file and decrypt it using GPG:
GITHUB_TOKEN=*gpg*b64*file:~/.github_token
Each derefer is applied in reverse, starting with "file" which loads the content of "~/.github_token". "b64" then decodes it and finally "gpg" decrypts it.
If the value of an environmental variable starts with Loader.Star (which defaults to "*"), it is treated as a pipeline. Otherwise, it's treated as a literal value and left unchagned. In the unlikely case where a literal value starting with Loader.Star is needed, the following can be used:
GLOB_PAT=*:*.terraform
Here the blank derefer treats everything after "*:" as literal and returns it, thus leading to GLOB_PAT being set to "*.terraform".
Package autoload registers a set of derefers that are included in derefer package with appropriate tags. To have more control over tags and the timing of when the loading happens, you can register each derefer manually and call Load() to populate the env vars.
Any type that implements Derefer methods can be registered and used in the pipeline.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Derefer ¶
Derefer is an interface that wraps Deref method.
Deref method is called with the recursively derefed value of all subsequent derefers in the pipeline. ref is therefore a literal by the time it's passed to this method.
type DereferFunc ¶
DereferFunc type is an adapter to allow use of ordinary functions as derefers.
type Loader ¶
type Loader struct {
// Star is the prefix and separator of derefer tags which defaults to "*".
Star string
// contains filtered or unexported fields
}
Loader holds a registry of derefers which are looked up and applied to values of all environmental variables when Load() is called.
func NewLoader ¶
func NewLoader() *Loader
NewLoader returns a new loader with empty "" tag mapped to to a passthrough derefer. This is needed to allow for environmental variable values which start with "*":
GLOB_PAT=*:*.terraform
The above will resolve to "*.terraform".