Last active
November 16, 2021 02:10
-
-
Save bscott/0d74bed506e36c59d4cf90b312ff775c to your computer and use it in GitHub Desktop.
Go Functions
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
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