modulepackage
0.2.2
Repository: https://github.com/berquerant/structconfig.git
Documentation: pkg.go.dev
# README
structconfig
Map default values, environment variables, and command-line arguments to struct tags.
Installation
go get github.com/berquerant/structconfig
Examples
Default values
type T struct {
I int `default:"10"`
}
sc := structconfig.New[T]()
var got T
if err := sc.FromDefault(&got); err != nil {
panic(err)
}
// got.I == 10
Environment variables
type T struct {
I int `name:"int_value"`
}
os.Setenv("INT_VALUE", "10")
sc := structconfig.New[T]()
var got T
if err := sc.FromEnv(&got); err != nil {
panic(err)
}
// got.I == 10
Command-line flags (pflag)
type T struct {
I int `name:"int_value" default:"10"`
}
var fs *pflag.FlagSet = // ...
sc := structconfig.New[T]()
if err := sc.SetFlags(fs); err != nil {
panic(err)
}
if err := fs.Parse([]string{"--int_value", "100"}); err != nil {
panic(err)
}
var got T
if err := sc.FromFlags(&got, fs); err != nil {
panic(err)
}
// got.I == 100
More examples
# Functions
No description provided by the author
New returns a new StructConfig.
No description provided by the author
No description provided by the author
NewMerger returns a new Merger.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author