envconf

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

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

Go to latest
Published: Dec 10, 2016 License: MIT Imports: 5 Imported by: 0

README

envconf

A Go (Golang) library for managing configuration data from environment variables which is used by my Twelve-Factor Apps.

GoDoc Travis CI Status Coverage Status Go Report Card

Installation

Download and install it:

go get -u github.com/sboehmann/envconf

Import it in your code:

import "github.com/sboehmann/envconf"

Quick start

First you need a few environment variables:

export MY_PORT=8080
export MY_MESSAGE="Hello World!"

And now a simple program that uses these variables:

package main

import (
    "github.com/sboehmann/envconf"
    "io"
    "net/http"
)

func message(w http.ResponseWriter, r *http.Request) {
    value, _ := envconf.GetString("MESSAGE")
    io.WriteString(w, value)
}

func main() {
    envconf.SetPrefix("MY_")

    http.HandleFunc("/", message)
    http.ListenAndServe(":"+envconf.MustGetString("PORT"), nil)
}

Documentation

Overview

Package envconf simplifies reading and writing environment variables. A typical use is using environment variables for configuration settings.

Use of this source code is governed by the MIT License that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool

func GetBool(key string) (value bool, ok bool)

GetBool ...

func GetDuration

func GetDuration(key string) (value time.Duration, ok bool)

GetDuration returns the environment parsed as time.Duration.

func GetFloat64

func GetFloat64(key string) (value float64, ok bool)

GetFloat64 returns the environment parsed as float64.

func GetInt

func GetInt(key string) (value int, ok bool)

GetInt returns the environment parsed as int.

func GetInt64

func GetInt64(key string) (value int64, ok bool)

GetInt64 returns the environment parsed as int64.

func GetPrefix

func GetPrefix() string

GetPrefix returns the prefix that is automatically prepended to a environment variable.

func GetString

func GetString(key string) (value string, ok bool)

GetString returns the environment parsed as string. Returns an empty string if the environment does not exists or could not be parsed.

func GetUInt

func GetUInt(key string) (value uint, ok bool)

GetUInt returns the environment parsed as uint.

func GetUInt64

func GetUInt64(key string) (value uint64, ok bool)

GetUInt64 returns the environment parsed as uint64.

func IssetKey

func IssetKey(key string) bool

IssetKey determine if a environment variable is set.

func MustGetBool

func MustGetBool(key string) (value bool)

MustGetBool returns the environment variable parsed as bool if possible, otherwise it panics.

func MustGetDuration

func MustGetDuration(key string) time.Duration

MustGetDuration returns the environment variable parsed as time.Duration if possible, otherwise it panics.

func MustGetFloat64

func MustGetFloat64(key string) float64

MustGetFloat64 returns the environment variable parsed as float64 if possible, otherwise it panics.

func MustGetInt

func MustGetInt(key string) (value int)

MustGetInt returns the environment variable parsed as int if possible, otherwise it panics.

func MustGetInt64

func MustGetInt64(key string) (value int64)

MustGetInt64 returns the environment variable parsed as int64 if possible, otherwise it panics.

func MustGetString

func MustGetString(key string) (value string)

MustGetString returns the environment variable parsed as string if possible, otherwise it panics.

func MustGetUInt

func MustGetUInt(key string) (value uint)

MustGetUInt returns the environment variable parsed as uint if possible, otherwise it panics.

func MustGetUInt64

func MustGetUInt64(key string) (value uint64)

MustGetUInt64 returns the environment variable parsed as uint64 if possible, otherwise it panics.

func SetBool

func SetBool(key string, value bool)

SetBool sets the environment.

func SetDefaultBool

func SetDefaultBool(key string, value bool)

SetDefaultBool sets the environment if it is not already set.

func SetDefaultDuration

func SetDefaultDuration(key string, value time.Duration)

SetDefaultDuration sets the environment if it is not already set.

func SetDefaultFloat64

func SetDefaultFloat64(key string, value float64)

SetDefaultFloat64 sets the environment if it is not already set.

func SetDefaultInt

func SetDefaultInt(key string, value int)

SetDefaultInt sets the environment if it is not already set.

func SetDefaultInt64

func SetDefaultInt64(key string, value int64)

SetDefaultInt64 sets the environment if it is not already set.

func SetDefaultString

func SetDefaultString(key string, value string)

SetDefaultString sets the environment if it is not already set.

func SetDefaultUInt

func SetDefaultUInt(key string, value uint)

SetDefaultUInt sets the environment if it is not already set.

func SetDefaultUInt64

func SetDefaultUInt64(key string, value uint64)

SetDefaultUInt64 sets the environment if it is not already set.

func SetDuration

func SetDuration(key string, value time.Duration)

SetDuration sets the environment.

func SetFloat64

func SetFloat64(key string, value float64)

SetFloat64 sets the environment.

func SetInt

func SetInt(key string, value int)

SetInt sets the environment.

func SetInt64

func SetInt64(key string, value int64)

SetInt64 sets the environment.

func SetPrefix

func SetPrefix(p string)

SetPrefix sets the prefix which is automatically prepended to an environment variable.

func SetString

func SetString(key string, value string)

SetString sets the environment.

func SetUInt

func SetUInt(key string, value uint)

SetUInt sets the environment.

func SetUInt64

func SetUInt64(key string, value uint64)

SetUInt64 sets the environment.

func UnsetKey

func UnsetKey(key string)

UnsetKey unsets a single environment variable.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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