From 7cba7d11171a62c618b0187d2c6dd32b45740303 Mon Sep 17 00:00:00 2001 From: brent s Date: Sun, 29 May 2022 22:52:03 -0400 Subject: [PATCH] Adding env.HasEnv for single-value env exist logic --- envs/funcs.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/envs/funcs.go b/envs/funcs.go index 3fb22b9..3bc32de 100644 --- a/envs/funcs.go +++ b/envs/funcs.go @@ -118,3 +118,17 @@ func GetPidEnvMapNative(pid uint32) (envMap map[string]interface{}, err error) { return } + +/* + HasEnv is much like os.LookupEnv, but only returns a boolean for + if the environment variable key exists or not. + + This is useful anywhere you may need to set a boolean in a func call + depending on the *presence* of an env var or not. +*/ +func HasEnv(key string) (envIsSet bool) { + + _, envIsSet = os.LookupEnv(key) + + return +}