JSON configs in conjunction with Go's flag package
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
config.json
example_jsonflag_test.go
jsonflag.go
jsonflag_test.go
test_config.json

README.md

jsonflag

Go Report Card GoDoc

Use JSON configs in conjunction with Go's flag package.

See the godocs for documentation and a working example.

Example

type ExampleConfig struct {
	Flag1 string
	Flag2 string
	Flag3 int
}

func main(){
  var config ExampleConfig
  flag.StringVar(&config.Flag1, "flag1", "defaultFlag1", "flag1Desc")
  flag.StringVar(&config.Flag2, "flag2", "defaultFlag2", "flag2Desc")
  flag.IntVar(&config.Flag3, "flag3", 1, "flag3Desc")

  jsonflag.Parse(&config)
}

Example config.json file:

{
"flag1": "jsonFlag1",
"flag2": "jsonFlag2",
"flag3": 3,
}

Testing

USER=exampleUser go test --flag1=cliFlag1 --config=test_config.json