proxy.golang.org : github.com/pierrec/construct
Package construct provides a simple way to load configuration into a struct from multiple sources and formats, by relying on the struct embedded types and special interfaces. The goal is to reduce the code boilerplate used to initialize data structures to a minimum, by leveraging Go's types syntax definitions, interface methods, types reusability and by providing full support for complex field types (basic Go types, slices, maps and any combination of those.) For instance, when loading the data from the command line, instead of defining the cli options definitions using struct field tags, as it is usually done for cli parsing packages, the definitions are retrieved from the Config.Usage() method. This allows building definitions dynamically. A struct has its fields populated by calling the Load() function. The rules to populate the struct fields are as follow: fields are only processed if they are exported a field represents a config item for the Config interface an embedded type implementing the Config interface is used to group config items logically an embedded type implementing the Config and FromFlags interfaces represents a subcommand fields processing can be modified using field tags with the following format `... cfg:"[<key>][,<flag1>[,<flag2>]]" ...` If the key is "-", the field is ignored. If the key is not empty, the value is used as the field name. The following struct tag flags are currently supported: Subcommands in command line flags are defined by embedding a struct implementing both the Config and FromFlags interfaces. The FlagsDone() method is invoked on the last subcommand with the remaining command line arguments. Data used to populate structs can be fetched from various sources to override the current struct instance values in the following order: The data sources are defined by implementing the relevant interfaces on the struct: Once the data is loaded from all sources, the Init() method is invoked on the main struct as well as all the embedded ones except subcommands that have not been requested. The following types, as well as slices and maps of them, are supported: The FromIO interface is used to load and save the configuration from and to any kind of storage and using any format. Implementations for file based storage and widely used formats such as json, toml, yaml or ini are available in the construct/constructs package.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/pierrec/construct
License: BSD-3-Clause
Latest release: almost 8 years ago
First release: almost 8 years ago
Namespace: github.com/pierrec
Stars: 0 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 4 months ago