Making map of env vars singleton
@@ -6,8 +6,14 @@ import (
"github.com/projectdiscovery/stringsutil"
)
-// EnvVars returns a map with all environment variables into a map
-func EnvVars() map[string]interface{} {
+var envVars map[string]interface{}
+
+func init() {
+ // snapshot env vars at bootstrap
+ envVars = parseEnvVars()
+}
+
+func parseEnvVars() map[string]interface{} {
sliceEnvVars := os.Environ()
envVars := make(map[string]interface{}, len(sliceEnvVars))
for _, envVar := range sliceEnvVars {
@@ -16,3 +22,12 @@ func EnvVars() map[string]interface{} {
}
return envVars
}
+
+// EnvVars returns a map with all environment variables into a map
+func EnvVars() map[string]interface{} {
+ if envVars == nil {
+ envVars = parseEnvVars()
+ }
+
+ return envVars
+}
