-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent: Improve with changes from code review
- Loading branch information
Showing
5 changed files
with
41 additions
and
15 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
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,30 @@ | ||
package envs | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func ValidateEnvs(message string, envKeys []string) { | ||
|
||
for _, env := range envKeys { | ||
_, isSet := os.LookupEnv(env) | ||
if !isSet { | ||
panic(fmt.Sprintf(message, env)) | ||
} | ||
} | ||
|
||
} | ||
|
||
// Validates if env exists and converts it to int type, panics on error | ||
func ConvertToInt(env string) int { | ||
ValidateEnvs("%s env variable not set", []string{env}) | ||
|
||
envInt, err := strconv.Atoi(os.Getenv(env)) | ||
if err != nil { | ||
panic(fmt.Sprintf("%s has to be numeric", env)) | ||
} | ||
|
||
return envInt | ||
} |
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