2020-08-23 00:24:38 +03:00
|
|
|
package env
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Lukaesebrot/pasty/internal/static"
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"os"
|
2020-08-24 00:44:47 +03:00
|
|
|
"strconv"
|
2020-08-23 00:24:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Load loads an optional .env file
|
|
|
|
func Load() {
|
|
|
|
godotenv.Load()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns the content of the environment variable with the given key or the given fallback
|
|
|
|
func Get(key, fallback string) string {
|
|
|
|
found := os.Getenv(static.EnvironmentVariablePrefix + key)
|
|
|
|
if found == "" {
|
|
|
|
return fallback
|
|
|
|
}
|
|
|
|
return found
|
|
|
|
}
|
2020-08-24 00:44:47 +03:00
|
|
|
|
|
|
|
// Bool uses Get and parses it into a boolean
|
|
|
|
func Bool(key string, fallback bool) bool {
|
|
|
|
parsed, _ := strconv.ParseBool(Get(key, strconv.FormatBool(fallback)))
|
|
|
|
return parsed
|
|
|
|
}
|