envlib

package module
v0.0.0-...-d670f89 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2016 License: MIT Imports: 3 Imported by: 1

README

envlib

A go package to manipulate the environment with a simple approach.

This is a package that helps to edit environment files like those present on many Linux OSes (like /etc/environment) or the environment passed to a Docker container with the flag -env-file <file>. Environment files look like this:

VARIABLE1=value1
VARIABLE2=value2

This package simplify editing such files.

This package comes from the necesity of quickly editing environment files when changing environments (for example, setting http_proxy on and off, and is modeled arround this particular use case)

The Init function can take any standard Environ as such for example os.Environ() or you can choose to build your own Environ.

Then you can choose to Select which variables to keep, or to MergeWith a standard environment file, and finally maybe Persist to store the resulting environment file.

Check the directory examples for some use cases. You can run all the examples with:

cd examples
go generate -v ./...

Also check the tests for some other use cases.

Documentation

Overview

Go package to manipulate the environment

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Environ

func Environ() (environ []string)

Returns the envlib environment in standard representation, removing duplicates, ignoring empty variables

func Getenv

func Getenv(name string) string

Gets the named variable from the envlib environment

func Init

func Init(environ []string)

Initializes the envlib with the supplied environ

func MergeWith

func MergeWith(file string) (err error)

Merges the envlib environment with a file, the envlib environment have preference over the file

func Persist

func Persist(file string) (err error)

Store the envlib environment to a file

func Select

func Select(names Nameset)

Selects the Nameset of variables from the envlib environment

func ToString

func ToString() (s string)

Converts the envlib environment to the typical representation for files

Types

type Nameset

type Nameset map[string]int

A map that is used as a set

func NewNameset

func NewNameset(names ...string) (ns Nameset)

Create a new Nameset

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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