Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Envguard ¶
type Envguard struct {
// contains filtered or unexported fields
}
Envguard is a state of environment variables which will be restored at Restore() method call.
func All ¶
func All() *Envguard
All creates a new Envguard instance with all existing environment variables. All environment variables will be restored by calling Restore().
func New ¶
New creates a new Envguard instance. If one ore more keys are given, corresponding environment variables will be restored at Restore() method call.
func Setenvs ¶
Setenvs sets environment variables with given key-values. And creates a new Envguard instance to restore them when calling Restore().
func Unset ¶
Unset creates a new Envguard instance with unsetting all given anvironment variables. The unset variables will be restored by calling Restore() method. When underlying os.Unsetenv() failed, it returns an error.
func (*Envguard) Restore ¶
Restore restores stored environment variable values. This method is usually called with 'defer' to ensure the state to be restored. This function returns an error when underlying Setenv() calls returned an error except for on Windows. On Windows this function returns nil always since some environment variables are not set on Windows and it is intentional.