Add Go WireGuard panel with PostgreSQL 17 and Dokploy compose.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AppPort string
|
||||
AppURL string
|
||||
SiteName string
|
||||
DatabaseURL string
|
||||
SessionSecret string
|
||||
AdminUsername string
|
||||
AdminEmail string
|
||||
AdminPassword string
|
||||
MySQLDumpPath string
|
||||
AutoImportDump bool
|
||||
SecureCookies bool
|
||||
RememberDays int
|
||||
}
|
||||
|
||||
func Load() Config {
|
||||
return Config{
|
||||
AppPort: getenv("APP_PORT", "8080"),
|
||||
AppURL: strings.TrimRight(getenv("APP_URL", "http://localhost:8080"), "/"),
|
||||
SiteName: getenv("SITE_NAME", "Evilfox.cc"),
|
||||
DatabaseURL: getenv("DATABASE_URL", "postgres://wg:wg@localhost:5432/wg?sslmode=disable"),
|
||||
SessionSecret: getenv("SESSION_SECRET", "change-me-session-secret-32chars!!"),
|
||||
AdminUsername: getenv("ADMIN_USERNAME", "admin"),
|
||||
AdminEmail: getenv("ADMIN_EMAIL", "admin@evilfox.cc"),
|
||||
AdminPassword: getenv("ADMIN_PASSWORD", ""),
|
||||
MySQLDumpPath: getenv("MYSQL_DUMP_PATH", "/data/wg.sql"),
|
||||
AutoImportDump: getenvBool("AUTO_IMPORT_MYSQL", true),
|
||||
SecureCookies: getenvBool("SECURE_COOKIES", false),
|
||||
RememberDays: getenvInt("REMEMBER_DAYS", 30),
|
||||
}
|
||||
}
|
||||
|
||||
func (c Config) RememberDuration() time.Duration {
|
||||
return time.Duration(c.RememberDays) * 24 * time.Hour
|
||||
}
|
||||
|
||||
func getenv(key, def string) string {
|
||||
if v := strings.TrimSpace(os.Getenv(key)); v != "" {
|
||||
return v
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func getenvBool(key string, def bool) bool {
|
||||
v := strings.TrimSpace(os.Getenv(key))
|
||||
if v == "" {
|
||||
return def
|
||||
}
|
||||
b, err := strconv.ParseBool(v)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func getenvInt(key string, def int) int {
|
||||
v := strings.TrimSpace(os.Getenv(key))
|
||||
if v == "" {
|
||||
return def
|
||||
}
|
||||
n, err := strconv.Atoi(v)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
return n
|
||||
}
|
||||
Reference in New Issue
Block a user