environ

package module
v0.0.0-...-20a5710 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2015 License: MIT Imports: 7 Imported by: 1

README

Go-Environ GoDoc

Unix-like environment variable functions in Go

Go-Environ is a system to implement the similar functionality as environment lists found in all Unix-based OS'. Basically, all the functions found at "man 3 setenv" from a Unix prompt. With some additions to support Go's basic types.

Features

  • for convenience, it defaults to "overwrite" from the setenv() context.
  • Uses sync.pool to efficiently use resources when under heavy load.
  • get* functions for bool, float, and int.
  • Index and Contains functions to check for variable existence.

Installation

Using "go get":

go get github.com/codehack/go-environ

Then import from source:

import "github.com/codehack/go-environ"

Documentation

The full code documentation is located at GoDoc:

http://godoc.org/github.com/codehack/go-environ

Go-Environ is Copyright (c) 2014-present Codehack. Published under MIT License

Documentation

Overview

Package environ is a system to implement the similar functionality as environment lists found in all Unix-based OS'. Basically, all the functions found at "man 3 setenv" from a Unix prompt. With some additions to support Go's basic types.

Index

Constants

View Source
const Version = "0.2.3"

Version is the version of this package

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

type Env []string

Env is an environment list with name=value values.

func NewEnv

func NewEnv() *Env

NewEnv returns a new Env list (or from pool).

func (*Env) Contains

func (e *Env) Contains(name string) bool

Contains returns true if name is found in Env e.

func (*Env) Free

func (e *Env) Free()

Free returns this Env e back into the pool for further use. It's recommended to use this function when we are done using e.

func (*Env) Get

func (e *Env) Get(name string) string

Get returns the string value matching name in Env e, or empty "" if not found.

func (*Env) GetBool

func (e *Env) GetBool(name string) bool

GetBool returns the bool value matching name in Env e, or false if not found or the value is not a boolean.

func (*Env) GetFloat

func (e *Env) GetFloat(name string) float64

GetFloat returns the float value matching name in Env e, or 0 if not found or the value is not a float.

func (*Env) GetInt

func (e *Env) GetInt(name string) int

GetInt returns the int value matching name in Env e, or 0 if not found or the value is not an int.

func (*Env) GetTime

func (e *Env) GetTime(name string) time.Time

GetTime returns the time.Time value matching name in Env e, or time.Time{} if not found or the value is not a time.Time. The parsing is done using format: "2006-01-02 15:04:05.999999999 -0700 MST", which is a variation on time.RFC3339Nano. The returned value should be checked with time.IsZero()

func (*Env) Index

func (e *Env) Index(name string) int

Index returns the index of the first instance of name found in Env e, or -1 otherwise.

func (*Env) Print

func (e *Env) Print()

Print will print all name=value pairs to stdout.

func (*Env) Put

func (e *Env) Put(name, value string)

Put inserts name=value into Env e if a value matching name is not found. Otherwise it replaces the current name=value with the new value.

func (*Env) Set

func (e *Env) Set(name string, v interface{}) error

Set converts a known value type v to a string value and puts name=value in Env e. It returns nil if successful, error otherwise. Value types supported: bool, byte, uint (32 & 64), int (32 & 64), float32, float64 and string.

func (*Env) Unset

func (e *Env) Unset(name string)

Unset empties all values with found with name. Note that this function won't remove name=value pairs, just set value to empty string "".

Jump to

Keyboard shortcuts

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