39 lines
700 B
Go
39 lines
700 B
Go
package env
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
const (
|
|
Env EnvKey = "ENV"
|
|
PhotoDir EnvKey = "PHOTO_DIR"
|
|
Host EnvKey = "HOST"
|
|
Port EnvKey = "PORT"
|
|
IntervalDefault EnvKey = "INTERVAL_DEFAULT"
|
|
)
|
|
|
|
type EnvKey string
|
|
|
|
func Load(path string) error {
|
|
if path == "" {
|
|
path = ".env"
|
|
}
|
|
return godotenv.Load(path)
|
|
}
|
|
|
|
func (key EnvKey) GetValue() string {
|
|
return os.Getenv(string(key))
|
|
}
|
|
|
|
func (key EnvKey) SetValue(value string) {
|
|
os.Setenv(string(key), value)
|
|
}
|
|
|
|
func (key EnvKey) GetBoolValue() bool {
|
|
value := strings.ToLower(os.Getenv(string(key)))
|
|
return value == "true" || value == "1"
|
|
}
|