Documentation
¶
Overview ¶
Package environment defines object describing the current environment.
Index ¶
- Variables
- func ValidateEnvironmentVariables(vars ...IEnvironmentVariable) error
- type EnvVar
- type IEnvironment
- type IEnvironmentVariable
- func FindEnvironmentVariable(envvar string, envvars ...IEnvironmentVariable) (IEnvironmentVariable, error)
- func NewEnvironmentVariable(key, value string) IEnvironmentVariable
- func NewEnvironmentVariableWithValidation(key, value string, rules ...validation.Rule) IEnvironmentVariable
- func ParseEnvironmentVariable(variable string) (IEnvironmentVariable, error)
- func ParseEnvironmentVariables(variables ...string) (envVars []IEnvironmentVariable)
Constants ¶
This section is empty.
Variables ¶
var ( // IsEnvironmentVariableKey defines a validation rule for environment variable keys ([IEEE Std 1003.1-2008 / IEEE POSIX P1003.2/ISO 9945.2](http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02)) for use with github.com/go-ozzo/ozzo-validation // TODO use the built-in implementation in `is` package when https://github.com/go-ozzo/ozzo-validation/issues/186 is looked at. IsEnvironmentVariableKey = validation.NewStringRuleWithError(isEnvVarKey, errEnvvarInvalid) )
Functions ¶
func ValidateEnvironmentVariables ¶
func ValidateEnvironmentVariables(vars ...IEnvironmentVariable) error
ValidateEnvironmentVariables validates that environment variables are correctly defined in regard to their schema.
Types ¶
type EnvVar ¶
type EnvVar struct {
// contains filtered or unexported fields
}
func (*EnvVar) Equal ¶
func (e *EnvVar) Equal(v IEnvironmentVariable) bool
func (*EnvVar) MarshalText ¶
func (*EnvVar) UnmarshalText ¶
type IEnvironment ¶
type IEnvironment interface { // GetCurrentUser returns the environment current user. GetCurrentUser() *user.User // GetEnvironmentVariables returns the variables defining the environment (and optionally those supplied in `dotEnvFiles`) // `dotEnvFiles` corresponds to `.env` files present on the machine and follows the mechanism described by https://github.com/bkeepers/dotenv GetEnvironmentVariables(dotEnvFiles ...string) []IEnvironmentVariable // GetFilesystem returns the filesystem associated with the current environment GetFilesystem() filesystem.FS // GetEnvironmentVariable returns the environment variable corresponding to `envvar` or an error if it not set. optionally it searches `dotEnvFiles` files too // `dotEnvFiles` corresponds to `.env` files present on the machine and follows the mechanism described by https://github.com/bkeepers/dotenv GetEnvironmentVariable(envvar string, dotEnvFiles ...string) (IEnvironmentVariable, error) }
IEnvironment defines an environment for an application to run on.
func NewCurrentEnvironment ¶
func NewCurrentEnvironment() IEnvironment
NewCurrentEnvironment returns system current environment.
type IEnvironmentVariable ¶
type IEnvironmentVariable interface { encoding.TextMarshaler encoding.TextUnmarshaler fmt.Stringer // GetKey returns the variable key. GetKey() string // GetValue returns the variable value. GetValue() string // Validate checks whether the variable value is correctly defined Validate() error // Equal states whether two environment variables are equal or not. Equal(v IEnvironmentVariable) bool }
IEnvironmentVariable defines an environment variable to be set for the commands to run.
func FindEnvironmentVariable ¶ added in v1.49.0
func FindEnvironmentVariable(envvar string, envvars ...IEnvironmentVariable) (IEnvironmentVariable, error)
FindEnvironmentVariable looks for an environment variable in a list. if no environment variable matches, an error is returned
func NewEnvironmentVariable ¶
func NewEnvironmentVariable(key, value string) IEnvironmentVariable
NewEnvironmentVariable returns an environment variable defined by a key and a value.
func NewEnvironmentVariableWithValidation ¶
func NewEnvironmentVariableWithValidation(key, value string, rules ...validation.Rule) IEnvironmentVariable
NewEnvironmentVariableWithValidation returns an environment variable defined by a key and a value but with the possibility to define value validation rules.
func ParseEnvironmentVariable ¶
func ParseEnvironmentVariable(variable string) (IEnvironmentVariable, error)
ParseEnvironmentVariable parses an environment variable definition, in the form "key=value".
func ParseEnvironmentVariables ¶ added in v1.49.0
func ParseEnvironmentVariables(variables ...string) (envVars []IEnvironmentVariable)
ParseEnvironmentVariables parses a list of key=value entries such as os.Environ() and returns a list of the corresponding environment variables. Any entry failing parsing will be ignored.