environment

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Packege environment implements setting up and handling environment variables.

Any varible implementing the Formatter interface can be set as value to Map.

Example usage:

envMap := environment.Map{
    "OS": environemnt.String("linux"),
    "GOLANG": environment.True,
    "CORES": environment.Int(6),
}

env := envMap.IntoEnv()
// converted to environment.Env the result is
// env = {}string{"OS=linux", "GOLANG", "CORES=6"}

// alternatively the Map above could be created like so:
envMap := make(environment.Map)

envMap.Set("OS", "linux")
envMap.Use("GOLANG")
envMap.SetInt("CORES", 6)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

type Env struct {
	// contains filtered or unexported fields
}

Env is a struct representing a set of environment values.

func From

func From(i Into) (e Env, err error)

From uses the implemented IntoEnv function to convert i into an Env variable.

func New

func New(env []string) (e Env)

New creates an Env out of a string slice.

func (Env) Get

func (e Env) Get() (s []string)

Get returns the string slice representing the set of environment variables.

type Formatter

type Formatter interface {
	// FormatEnv will return with the string representation of an environment
	// variable given a specific key.
	FormatEnv(key string) string
}

Formatter is the value type for Map.

var True Formatter = trueVal{}

True represents that the environemnt variable is set.

type Int

type Int int

Int is an alias to int to implement the Formatter interface.

func (Int) FormatEnv

func (i Int) FormatEnv(key string) (out string)

FormatEnv implements the Formatter interface

type Into

type Into interface {
	IntoEnv() (Env, error)
}

Into represents any type that can be converted into an environment.Env variable.

type Map

type Map map[string]Formatter

Map represent key value pairs of environment variables

func (Map) IntoEnv

func (m Map) IntoEnv() (env Env, err error)

IntoEnv converts m into an Env

func (Map) Remove

func (m Map) Remove(key string)

Remove removes a key from the map.

func (Map) Set

func (m Map) Set(key, val string)

Set sets key to String(val).

func (Map) SetInt

func (m Map) SetInt(key string, val int)

SetInt sets key to Int(val).

func (Map) Use

func (m Map) Use(key string)

Use sets key to True.

type String

type String string

String is an alias to string to implement the Formatter interface.

func (String) FormatEnv

func (s String) FormatEnv(key string) (out string)

FormatEnv implements the Formatter interface

Jump to

Keyboard shortcuts

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