diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2024-09-30 11:16:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-30 11:16:28 -0400 |
| commit | 18791a4e6e08de406e9c1e257cc4be2a85f29eea (patch) | |
| tree | 0a32b7b821a229e0bbdf11775f3e66c2fce24217 /internal/datafs | |
| parent | 69d3e0c46e34a57e6cfcb58d36b28c6f0beb134e (diff) | |
feat(config): Allow avoiding reading default config file (#2227)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'internal/datafs')
| -rw-r--r-- | internal/datafs/getenv.go | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/internal/datafs/getenv.go b/internal/datafs/getenv.go index 5f9761d4..6af03508 100644 --- a/internal/datafs/getenv.go +++ b/internal/datafs/getenv.go @@ -15,7 +15,7 @@ func ExpandEnvFsys(fsys fs.FS, s string) string { // GetenvFsys - a convenience function intended for internal use only! func GetenvFsys(fsys fs.FS, key string, def ...string) string { - val := getenvFile(fsys, key) + val, _ := getenvFile(fsys, key) if val == "" && len(def) > 0 { return def[0] } @@ -23,22 +23,28 @@ func GetenvFsys(fsys fs.FS, key string, def ...string) string { return val } -func getenvFile(fsys fs.FS, key string) string { - val := os.Getenv(key) +// LookupEnvFsys - a convenience function intended for internal use only! +func LookupEnvFsys(fsys fs.FS, key string) (string, bool) { + return getenvFile(fsys, key) +} + +func getenvFile(fsys fs.FS, key string) (string, bool) { + val, found := os.LookupEnv(key) if val != "" { - return val + return val, true } p := os.Getenv(key + "_FILE") if p != "" { val, err := readFile(fsys, p) if err != nil { - return "" + return "", false } - return strings.TrimSpace(val) + + return strings.TrimSpace(val), true } - return "" + return "", found } func readFile(fsys fs.FS, p string) (string, error) { |
