An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 1.8% on proxy.golang.org
Top 0.5% dependent packages on proxy.golang.org
Top 0.6% dependent repos on proxy.golang.org
Top 3.7% forks on proxy.golang.org
Top 1.0% docker downloads on proxy.golang.org

proxy.golang.org : github.com/olebedev/config

Package config provides convenient access methods to configuration stored as JSON or YAML. Let's start with a simple YAML file config.yml: We can parse it using ParseYaml(), which will return a *Config instance on success: An equivalent JSON configuration could be built using ParseJson(): From now, we can retrieve configuration values using a path in dotted notation: Besides String(), other types can be fetched directly: Bool(), Float64(), Int(), Map() and List(). All these methods will return an error if the path doesn't exist, or the value doesn't match or can't be converted to the requested type. A nested configuration can be fetched using Get(). Here we get a new *Config instance with a subset of the configuration: Then the inner values are fetched relatively to the subset: For lists, the dotted path must use an index to refer to a specific value. To retrieve the information from a user stored in the configuration above: JSON or YAML strings can be created calling the appropriate Render*() functions. Here's how we render a configuration like the one used in these examples: This results in a configuration string to be stored in a file or database. For more more convenience it can parse OS environment variables and command line arguments. We can also specify the order of parsing: In case of OS environment all existing at the moment of parsing keys will be scanned in OS environment, but in uppercase and the separator will be `_` instead of a `.`. If EnvPrefix() is used the given prefix will be used to lookup the environment variable, e.g PREFIX_FOO_BAR will set foo.bar. In case of flags separator will be `-`. In case of command line arguments possible to use regular dot notation syntax for all keys. For see existing keys we can run application with `-h`. We can use unsafe method to get value: There is unsafe methods, like regular, but wuth prefix `U`.

Registry - Source - Documentation - JSON - codemeta.json
purl: pkg:golang/github.com/olebedev/config
Keywords: configuration , golang , json , yaml
License: MIT
Latest release: about 3 years ago
First release: about 10 years ago
Namespace: github.com/olebedev
Dependent packages: 77
Dependent repositories: 97
Stars: 261 on GitHub
Forks: 45 on GitHub
Docker dependents: 14
Docker downloads: 4,415
See more repository details: repos.ecosyste.ms
Last synced: 2 days ago

    Loading...
    Readme
    Loading...