env

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

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

Go to latest
Published: Sep 2, 2018 License: MIT Imports: 5 Imported by: 0

README

env

go environment/flag variable management.

Priority:

  • flag > environment > default
package main

import "github.com/jklaw90/env"

func main() {
	
    config := env.NewConfig(env.OptionPanicOnMissing, env.OptionLogOn). // define options here
		AddEnv("KEY", "value", "description here").
		AddEnv("DEBUG", "true", "some bool for xyz").
		AddEnv("OVER", "9000", "some int").
		AddFlagEnv("FLAG_CASE", "flagcase", "special", "special env name") // will use flag if specified
	
    env := env.New(config)
    
    // examples
	println(env.Get("KEY"))       // "value" unless environment var defined for KEY
	println(env.GetBool("DEBUG")) // true unless environment var defined for DEBUG
	println(env.GetInt("OVER"))   // 9000 unless environment var defined for OVER
	println(env.Get("FLAG_CASE")) // "special" unless environment var defined for FLAG_CASE or flagcase flag was set
    println(env.Get("SLKDFJKLSDFJ")) // Logs missing variable name if option set

    // for global use if needed...
	println(env.Get("KEY")) // "value"
}                                                                      

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(configName string) string

Get returns the env variables as a string based on the string name.

func GetBool

func GetBool(configName string) bool

GetBool returns the env variable as and bool based on the string name.

func GetInt

func GetInt(configName string) int

GetInt returns the env variable as and int based on the string name.

func New

func New(config Config) *env

New Create env

func OptionLogOn

func OptionLogOn(g *env)

func OptionPanicOnMissing

func OptionPanicOnMissing(g *env)

Types

type Config

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

func NewConfig

func NewConfig(options ...envOptions) Config

func (Config) AddEnv

func (c Config) AddEnv(key, defaultValue, description string) Config

func (Config) AddFlagEnv

func (c Config) AddFlagEnv(key, flagKey, defaultValue, description string) Config

type Variable

type Variable struct {
	Key         string
	Default     string
	Description string
	FlagKey     string
}

Jump to

Keyboard shortcuts

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