Initial commit
This commit is contained in:
37
cpone-dashboard/config/config.go
Normal file
37
cpone-dashboard/config/config.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user