Skip to content

Instantly share code, notes, and snippets.

@cmelgarejo
Created July 14, 2019 00:06
Show Gist options
  • Save cmelgarejo/8479904f9162242561ccda2851ddf88c to your computer and use it in GitHub Desktop.
Save cmelgarejo/8479904f9162242561ccda2851ddf88c to your computer and use it in GitHub Desktop.
package utils
import (
"log"
"os"
"strconv"
)
// MustGet will return the env or panic if it is not present
func MustGet(k string) string {
v := os.Getenv(k)
if v == "" {
log.Panicln("ENV missing, key: " + k)
}
return v
}
// MustGetBool will return the env as boolean or panic if it is not present
func MustGetBool(k string) bool {
v := os.Getenv(k)
if v == "" {
log.Panicln("ENV missing, key: " + k)
}
b, err := strconv.ParseBool(v)
if err != nil {
log.Panicln("ENV err: [" + k + "]\n" + err.Error())
}
return b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment