68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
AppsDir string
|
|
PortRangeStart int
|
|
PortRangeEnd int
|
|
ScanInterval time.Duration
|
|
Domain string
|
|
}
|
|
|
|
func Load() *Config {
|
|
port := os.Getenv("PAAS_PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
|
|
appsDir := os.Getenv("PAAS_APPS_DIR")
|
|
if appsDir == "" {
|
|
// Se existir /apps (dentro do container), usa ele; senão usa ./apps local para testes
|
|
if _, err := os.Stat("/apps"); err == nil {
|
|
appsDir = "/apps"
|
|
} else {
|
|
appsDir = "./apps"
|
|
}
|
|
}
|
|
|
|
startPort := getEnvInt("PAAS_PORT_START", 8001)
|
|
endPort := getEnvInt("PAAS_PORT_END", 8999)
|
|
|
|
scanSeconds := getEnvInt("PAAS_SCAN_INTERVAL", 3)
|
|
if scanSeconds < 1 {
|
|
scanSeconds = 3
|
|
}
|
|
|
|
domain := os.Getenv("PAAS_DOMAIN")
|
|
if domain == "" {
|
|
domain = "paas.weltonmoura.com.br"
|
|
}
|
|
|
|
return &Config{
|
|
Port: port,
|
|
AppsDir: appsDir,
|
|
PortRangeStart: startPort,
|
|
PortRangeEnd: endPort,
|
|
ScanInterval: time.Duration(scanSeconds) * time.Second,
|
|
Domain: domain,
|
|
}
|
|
}
|
|
|
|
func getEnvInt(key string, defaultVal int) int {
|
|
v := os.Getenv(key)
|
|
if v == "" {
|
|
return defaultVal
|
|
}
|
|
n, err := strconv.Atoi(v)
|
|
if err != nil {
|
|
return defaultVal
|
|
}
|
|
return n
|
|
}
|