Name: configure
Owner: Clever
Description: Seamlessly configure applications with either flags or JSON
Created: 2016-01-12 19:40:21.0
Updated: 2018-05-24 00:00:13.0
Pushed: 2018-05-24 00:00:12.0
Size: 21
Language: Go
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Easily fill in a configuration struct with either flag arguments or a JSON blob argument.
Given a simple program that uses two arguments, district_id
and collection
:
config struct {
DistrictID string `config:"district_id,required"`
Collection string `config:"collection"`
main() {
if err := configure.Configure(&config); err != nil {
log.Fatalf("err: %#v", err)
}
log.Printf("config: %#v", config)
// go use arguments to do something
It can be invoked two styles:
ample -h
e of ./example:
ollection string
generated field
istrict_id string
generated field
ample -district_id="abc123"
nfig: {DistrictID:abc123 Collection:}
ample '{"district_id":"abc123","collection":"schools"}'
nfig: {DistrictID:abc123 Collection:schools}
ample -district_id="abc123" -collection="schools"
nfig: {DistrictID:abc123 Collection:schools}
ils when not provided with the required district_id argument
ample -collection=schools
r: Missing required fields: [district_id]
ample '{"collection":"schools"}'
r: Missing required fields: [district_id]
You can also define defaults by passing a pre-populated struct:
main() {
config := struct {
DistrictID string `config:"district_id,required"`
Collection string `config:"collection"`
}{
Collection: "default-collection",
}
if err := configure.Configure(&config); err != nil {
log.Fatalf("err: %#v", err)
}
log.Printf("config: %#v\n", config)
// go use arguments to do something