Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 1.41 KB

README.md

File metadata and controls

55 lines (39 loc) · 1.41 KB

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)
}