From d4c803c41c7d1322cd3a3e7975bc10c6adb69a59 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 16 May 2022 14:53:48 +0200 Subject: [PATCH] doc(env): added missing docstring & README --- src/env/README.md | 7 +++++++ src/env/env.v | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 src/env/README.md diff --git a/src/env/README.md b/src/env/README.md new file mode 100644 index 00000000..135e8fa9 --- /dev/null +++ b/src/env/README.md @@ -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 diff --git a/src/env/env.v b/src/env/env.v index 3d07d235..5ed19552 100644 --- a/src/env/env.v +++ b/src/env/env.v @@ -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'