-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #916 from projectdiscovery/643-feature-env-variabl…
…es-support Adding support for global env variables
- Loading branch information
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package generators | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/projectdiscovery/stringsutil" | ||
) | ||
|
||
var envVars map[string]interface{} | ||
|
||
func parseEnvVars() map[string]interface{} { | ||
sliceEnvVars := os.Environ() | ||
parsedEnvVars := make(map[string]interface{}, len(sliceEnvVars)) | ||
for _, envVar := range sliceEnvVars { | ||
key, val := stringsutil.Before(envVar, "="), stringsutil.After(envVar, "=") | ||
parsedEnvVars[key] = val | ||
} | ||
return parsedEnvVars | ||
} | ||
|
||
// EnvVars returns a map with all environment variables into a map | ||
func EnvVars() map[string]interface{} { | ||
if envVars == nil { | ||
envVars = parseEnvVars() | ||
} | ||
|
||
return envVars | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters