- Notifications
You must be signed in to change notification settings - Fork4
conflag is a drop-in replacement for Go's standard flag package with config file support.
License
NotificationsYou must be signed in to change notification settings
nadoo/conflag
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
conflag is a drop-in replacement for Go's standard flag package with config file support.
package mainimport ("fmt""github.com/nadoo/conflag")varconfstruct {NamestringAgeintMalebool}funcmain() {// get a new conflag instanceflag:=conflag.New()// setup flags as the standard flag packageflag.StringVar(&conf.Name,"name","","your name")flag.IntVar(&conf.Age,"age",0,"your age")flag.BoolVar(&conf.Male,"male",false,"your sex")// parse before access flagsflag.Parse()// now you're able to get the parsed flag valuesfmt.Printf(" Name: %s\n",conf.Name)fmt.Printf(" Age: %d\n",conf.Age)fmt.Printf(" Male: %v\n",conf.Male)}
command:
example -name Jay -age 30
output:
Name: Jay Age: 30 Male:false
example.conf:
name={$NAME}age=20male
command:use "-config" flag to specify the config file path.
NAME=Jason example -config example.conf
output:
Name: Jason Age: 20 Male:true
example.conf:
name=Jasonage=20male
command:
example -config example.conf -name Michael
output:
Name: Michael Age: 20 Male:true
- format: KEY=VALUE
just use the command line flag name as key name:
## config file# comment line starts with "#"# format:#KEY=VALUE,# just use the command line flag name as key name# use {$ENV_VAR_NAME} in VALUE to get the Environment Variable value# your namename={$NAME}# your ageage=20# are you male?male=true# use include to include more config filesinclude=part1.inc.confinclude=part2.inc.conf
Seeexample.conf
About
conflag is a drop-in replacement for Go's standard flag package with config file support.
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published