Skip to content

Commit

Permalink
change to os.LookupEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
tc80 committed Jul 4, 2020
1 parent b05ab3f commit b20fccc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 1 addition & 2 deletions sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

// Init Sentry client
func Init() {
sentryDsn := os.Getenv("SENTRY_DSN")
if sentryDsn != "" {
if sentryDsn, ok := os.LookupEnv("SENTRY_DSN"); ok {
util.Check(sentry.Init(sentry.ClientOptions{
Dsn: sentryDsn,
}))
Expand Down
17 changes: 11 additions & 6 deletions util/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ const (

// GetEnv gets an environment variable, panicking if it is empty.
func GetEnv(name string) string {
v := os.Getenv(name)
if v == "" {
panic(fmt.Sprintf("Env %s is missing\n", name))
if v, ok := os.LookupEnv(name); ok {
return v
}
return v
panic(fmt.Sprintf("Env %s is missing\n", name))
}

// EnvExists determines if an environment variable exists.
func EnvExists(name string) bool {
_, ok := os.LookupEnv(name)
return ok
}

// IsDebug returns true if debug mode is enabled based
// on an environment variable.
func IsDebug() bool {
return os.Getenv("DEBUG") != ""
return EnvExists("DEBUG")
}

// GetBotBasePath gets the bot base path from an environment variable.
Expand All @@ -39,5 +44,5 @@ func GetCDNJSPackages() string {
// HasHTTPProxy returns true if the http proxy environment
// variable is set.
func HasHTTPProxy() bool {
return os.Getenv("HTTP_PROXY") != ""
return EnvExists("HTTP_PROXY")
}

0 comments on commit b20fccc

Please sign in to comment.