Skip to content

Commit

Permalink
Merged fbonalair#29 (_FILE) from original repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbferris committed Aug 27, 2023
1 parent a4d570e commit 74d2e59
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ func OptionalEnv(varName string, optional string) string {
}

/*
Check for an environment variable value, exit program if not found
Check for an environment variable value or the equivalent docker secret, exit program if not found
*/
func RequiredEnv(varName string) string {
envVar := os.Getenv(varName)
if envVar == "" {
envVarFileName := os.Getenv(varName + "_FILE")
if envVar == "" && envVarFileName == "" {
log.Fatalf("The required env var %s is not provided. Exiting", varName)
}
} else if envVar == "" && envVarFileName != "" {
envVarFromFile, err := os.ReadFile(envVarFileName)
if err != nil {
log.Fatalf("Could not read env var from file %s (Error: %v). Exiting", envVarFileName, err)
}
return string(envVarFromFile)
return envVar
}

Expand Down

0 comments on commit 74d2e59

Please sign in to comment.