68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
DBPath string
|
|
AdminUsername string
|
|
AdminPassword string
|
|
JWTSecret string
|
|
CrawlerIntervalMinutes int
|
|
CrawlerWorkers int
|
|
}
|
|
|
|
func LoadConfig() *Config {
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
|
|
dbPath := os.Getenv("DB_PATH")
|
|
if dbPath == "" {
|
|
dbPath = "./data/rsspipe.db"
|
|
}
|
|
|
|
adminUser := os.Getenv("ADMIN_USERNAME")
|
|
if adminUser == "" {
|
|
adminUser = "admin"
|
|
}
|
|
|
|
adminPass := os.Getenv("ADMIN_PASSWORD")
|
|
if adminPass == "" {
|
|
adminPass = "admin123456"
|
|
}
|
|
|
|
jwtSecret := os.Getenv("JWT_SECRET")
|
|
if jwtSecret == "" {
|
|
jwtSecret = "rsspipe-super-secret-jwt-key-2026"
|
|
}
|
|
|
|
intervalMin := 15
|
|
if intervalStr := os.Getenv("CRAWLER_INTERVAL_MINUTES"); intervalStr != "" {
|
|
if v, err := strconv.Atoi(intervalStr); err == nil && v > 0 {
|
|
intervalMin = v
|
|
}
|
|
}
|
|
|
|
workers := 10
|
|
if workerStr := os.Getenv("CRAWLER_WORKERS"); workerStr != "" {
|
|
if v, err := strconv.Atoi(workerStr); err == nil && v > 0 {
|
|
workers = v
|
|
}
|
|
}
|
|
|
|
return &Config{
|
|
Port: port,
|
|
DBPath: dbPath,
|
|
AdminUsername: adminUser,
|
|
AdminPassword: adminPass,
|
|
JWTSecret: jwtSecret,
|
|
CrawlerIntervalMinutes: intervalMin,
|
|
CrawlerWorkers: workers,
|
|
}
|
|
}
|