Skip to content

Instantly share code, notes, and snippets.

@bscott
Last active November 16, 2021 02:10
Show Gist options
  • Save bscott/0d74bed506e36c59d4cf90b312ff775c to your computer and use it in GitHub Desktop.
Save bscott/0d74bed506e36c59d4cf90b312ff775c to your computer and use it in GitHub Desktop.
Go Functions
func getEnvBool(key string) bool {
val := os.Getenv(key)
if val == "" {
return false
}
v, err := strconv.ParseBool(val)
if err != nil {
return false
}
return v
}
func getEnvInt(key string) (int, bool) {
val := os.Getenv(key)
if val == "" {
return 0, false
}
v, err := strconv.Atoi(val)
if err != nil {
return 0, false
}
return v, true
}
// Read from file
func read_secret(file string) string {
content, err := ioutil.ReadFile(file)
if err != nil {
log.Fatal(err)
}
text := string(content)
return text
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment