chore: added readme
parent
fca58e3da0
commit
adb161ca6d
52
README.md
52
README.md
|
@ -2,3 +2,55 @@
|
||||||
|
|
||||||
Vconf is a small V library for loading in configuration from a TOML config file
|
Vconf is a small V library for loading in configuration from a TOML config file
|
||||||
and/or environment variables.
|
and/or environment variables.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Vconf works by reading configuration variables from both a TOML file and/or
|
||||||
|
environment variables.
|
||||||
|
|
||||||
|
```v
|
||||||
|
struct Config {
|
||||||
|
pub:
|
||||||
|
port int = 8000
|
||||||
|
log_level string = 'WARN'
|
||||||
|
pkg_dir string
|
||||||
|
data_dir string
|
||||||
|
api_key string
|
||||||
|
default_arch string
|
||||||
|
global_schedule string = '0 3'
|
||||||
|
base_image string = 'archlinux:base-devel'
|
||||||
|
max_log_age int = -1
|
||||||
|
log_removal_schedule string = '0 0'
|
||||||
|
collect_metrics bool [empty_default]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is an example of a configuration struct. The configuration can then be
|
||||||
|
processed as follows:
|
||||||
|
|
||||||
|
```v
|
||||||
|
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
|
||||||
|
```
|
||||||
|
|
||||||
|
Configuration is defined completely as a V struct.
|
||||||
|
|
||||||
|
## Progress
|
||||||
|
|
||||||
|
My goal is to eventually support most types that the TOML library supports.
|
||||||
|
Currently supported:
|
||||||
|
|
||||||
|
- [ ] `Date`
|
||||||
|
- [ ] `DateTime`
|
||||||
|
- [ ] `Time`
|
||||||
|
- [x] `bool`
|
||||||
|
- [ ] `f32`
|
||||||
|
- [ ] `f64`
|
||||||
|
- [ ] `i64`
|
||||||
|
- [x] `int`
|
||||||
|
- [x] string
|
||||||
|
- [ ] `u64`
|
||||||
|
- [ ] `[]Any`
|
||||||
|
- [ ] `map[string]Any`
|
||||||
|
|
||||||
|
With the last one, my plan is to have this be another struct inside the
|
||||||
|
top-level one. Configuration could then be defined recursively.
|
||||||
|
|
Loading…
Reference in New Issue