envflagset

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

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

Go to latest
Published: Mar 27, 2017 License: MIT Imports: 6 Imported by: 1

README

envflagset

Parse FlagSet from ENV

example


import (
	"flag"
	envcfg "lcgc/platform/envflagset"
)

var (
	fs           *flag.FlagSet
	HttpListen   string
	CoreDSN      string
)

func init() {
	fs = envcfg.New("app", "0.0.1")
	fs.StringVar(&HttpListen, "http-listen", "localhost:5000", "bind address and port")
	fs.StringVar(&CoreDSN, "core-dsn", "mysql://user:pass@localhost:3306/appdb", "core database connecting string")
}

func main() {
	envcfg.Parse()
	// start app
}

// env:
// export APP_HTTP_LISTEN="localhost:5002"
// ./app

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(fs *flag.FlagSet, prefix string)

func New

func New(name, version string) *flag.FlagSet

func Parse

func Parse()

func ParseEnv

func ParseEnv(fs *flag.FlagSet, prefix string) error

ParseEnv parses all registered flags in the given flagset, and if they are not already set it attempts to set their values from environment variables. Environment variables take the name of the flag but are UPPERCASE, have the prefix "PREFIX_", and any dashes are replaced by underscores - for example: some-flag => PREFIX_SOME_FLAG

func SetPrefix

func SetPrefix(name string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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