Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 657 Bytes

File metadata and controls

33 lines (22 loc) · 657 Bytes

envtoflag GoDoc

envtoflag is a lib to populate flags from environment variables (to support http://12factor.net/config)

USage

package main

import (
	"flag"
	"log"

	"github.com/saj1th/envtoflag"
)

func main() {
	var (
		mode string // dev|debug|prod
		port int    // port to listen to
	)

	flag.StringVar(&mode, "mode", "", "dev|debug|prod")
	flag.IntVar(&port, "port", 8080, "port to listen to")
	
	// export YOURPACKAGENAME_PORT=9090	
	envtoflag.Parse("yourpackagename")

	fmt.Printf("Mode: %s\nPort: %d\n\n", mode, port)

}