env

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2019 License: MIT Imports: 6 Imported by: 0

README

env CircleCI

an easier to use environment variable package for gophers

installation

as with all other go packages, you know what to do:

go get github.com/rocketbitz/env

usage

go should probably have its own, but it doesn't, so here you are:

package main

import (
	"fmt"

	"github.com/rocketbitz/env"
)

func main() {
    env.SetDefault("DEFAULT_ENV", "default_value")
    env.Get("DEFAULT_ENV")  // "default_value"

    env.Set("DEFAULT_ENV", "explicit_value")
    env.Get("DEFAULT_ENV")  // "explicit_value"

    env.Count() // 1

    env.JSON()
    /*
    [
        {
            "key": "DEFAULT_ENV",
            "value": "explicit_value",
        }
    ]
    */
}

contribute

pr's are welcome. if they're awesome, they'll get reviewed and merged. if they're not, they'll get reviewed and closed, hopefully with a kind comment as to the reason.

license

MIT ...move along, move along.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count() int

Count the number of environment variables set, default and explicit

func DefaultCount

func DefaultCount() (count int)

DefaultCount is the number of environment variables, defaults only

func ExplicitCount

func ExplicitCount() int

ExplicitCount is the number of environment variables, explicit only

func Get

func Get(key string) (value string)

Get a given environment variable by name, returns a default value if the variable is not set

func JSON

func JSON() []byte

JSON representation of the environment, defaults included

func Print

func Print()

Print the environment, defaults included

func Set

func Set(key, value string) bool

Set an environment variable, returns true if the value was already set by either default or the environment itself

func SetDefault

func SetDefault(key, value string)

SetDefault registers a string as a default value for an environment variable

func SetDefaults

func SetDefaults(defaults map[string]string)

SetDefaults registers a map[string]string as default values for environment variables

func String

func String() string

String representation (in JSON) of the environment, defaults included

Types

type Var

type Var struct {
	Key     string `json:"key"`
	Value   string `json:"value"`
	Default bool   `json:"default,omitempty"`
}

Var represents an environment variable, default or set by the environment itself

Jump to

Keyboard shortcuts

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