60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package env
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
type EnvKey string
|
|
|
|
const (
|
|
Env EnvKey = "ENV"
|
|
GinMode EnvKey = "GIN_MODE"
|
|
Debug EnvKey = "DEBUG"
|
|
PrivKey EnvKey = "PRIVKEY"
|
|
Fullchain EnvKey = "FULLCHAIN"
|
|
Https EnvKey = "HTTPS"
|
|
Url EnvKey = "URL"
|
|
Port EnvKey = "PORT"
|
|
WorkingDir EnvKey = "WORKING_DIR"
|
|
Spa EnvKey = "SPA"
|
|
AccessSecret EnvKey = "ACCESS_SECRET"
|
|
RefreshSecret EnvKey = "REFRESH_SECRET"
|
|
)
|
|
|
|
const (
|
|
EnvDevelopment = "development"
|
|
EnvProduction = "Prodction"
|
|
)
|
|
|
|
func (key EnvKey) GetValue() string {
|
|
return os.Getenv(string(key))
|
|
}
|
|
|
|
func (key EnvKey) GetBoolValue() bool {
|
|
return strings.ToLower(os.Getenv(string(key))) == "true"
|
|
}
|
|
|
|
func (key EnvKey) GetUIntValue() uint {
|
|
value, err := strconv.ParseUint(os.Getenv(string(key)), 10, 32)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
return uint(value)
|
|
}
|
|
|
|
func Load(file string) error {
|
|
return godotenv.Load(file)
|
|
}
|
|
|
|
func InDevelopmentMode() bool {
|
|
return Env.GetValue() == EnvDevelopment
|
|
}
|
|
|
|
func InDebugMode() bool {
|
|
return strings.ToLower(Debug.GetValue()) == "true"
|
|
}
|