doc(env): added missing docstring & README
ci/woodpecker/pr/docs Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/build Pipeline was successful Details
ci/woodpecker/pr/docker Pipeline was successful Details
ci/woodpecker/pr/test Pipeline was successful Details

pull/183/head
Jef Roosens 2022-05-16 14:53:48 +02:00
parent 055b168ff1
commit d4c803c41c
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 12 additions and 0 deletions

7
src/env/README.md vendored 100644
View File

@ -0,0 +1,7 @@
This module provides a framework for parsing a configuration, defined as a
struct, from both a TOML configuration file & environment variables. Some
notable features are:
* Overwrite values in config file using environment variables
* Allow default values in config struct
* Read environment variable value from file

5
src/env/env.v vendored
View File

@ -11,6 +11,11 @@ const (
file_suffix = '_FILE'
)
// get_env_var tries to read the contents of the given environment variable. It
// looks for either `${env.prefix}${field_name.to_upper()}` or
// `${env.prefix}${field_name.to_upper()}${env.file_suffix}`, returning the
// contents of the file instead if the latter. If both or neither exist, the
// function returns an error.
fn get_env_var(field_name string) ?string {
env_var_name := '$env.prefix$field_name.to_upper()'
env_file_name := '$env.prefix$field_name.to_upper()$env.file_suffix'