Files
cpone_dashboard/cpone-dashboard/config/config.go
2026-04-30 14:27:01 +07:00

38 lines
712 B
Go

package config
import (
"log"
"os"
"github.com/joho/godotenv"
)
type Config struct {
AppPort string
DBDSN string
AuthSecret string
PDFBaseURL string
BasePath string // e.g. "/cpone-dashboard" or "" for root
}
func Load() *Config {
if err := godotenv.Load(); err != nil {
log.Println("no .env file, reading from environment")
}
return &Config{
AppPort: getEnv("APP_PORT", "8080"),
DBDSN: getEnv("DB_DSN", ""),
AuthSecret: getEnv("AUTH_SECRET", "cpone-change-this-secret"),
PDFBaseURL: getEnv("PDF_BASE_URL", ""),
BasePath: getEnv("BASE_PATH", ""),
}
}
func getEnv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}