Files
docker-compose-updater/internal/config/config.go
T
ilovintit cea9b941cf
Build and Push / build (push) Failing after 13m20s
Initial commit: docker-compose-updater
Go 项目,包含:
- 服务端 updater:两阶段协议,ECDSA 签名验证,AES-GCM 加密
- 发送端 dcu-send:Gitea Action CLI
- internal/auth:加解密/签名/会话管理
- internal/docker:Docker CLI 容器查找/拉取/重建
- action/:Gitea Action 定义
- deploy/Dockerfile:多阶段构建
- .gitea/workflows/build.yaml:CI/CD
2026-06-08 15:16:46 +08:00

57 lines
1.3 KiB
Go

// Package config 提供全局配置,全部通过环境变量设置。
package config
import (
"os"
"time"
)
// Config 应用配置。
type Config struct {
// 监听地址
Listen string
// Docker 操作超时
DockerPullTimeout time.Duration
DockerRestartTimeout time.Duration
// 会话密钥 TTL
SessionTTL time.Duration
// Nonce 缓存 TTL
NonceTTL time.Duration
// 时间戳容忍窗口
TimestampWindow time.Duration
// 日志级别
LogLevel string
}
// Load 从环境变量加载配置,未设置则用默认值。
func Load() *Config {
return &Config{
Listen: getEnv("LISTEN", ":8080"),
DockerPullTimeout: getDuration("DOCKER_PULL_TIMEOUT", 5*time.Minute),
DockerRestartTimeout: getDuration("DOCKER_RESTART_TIMEOUT", 30*time.Second),
SessionTTL: getDuration("SESSION_TTL", 30*time.Second),
NonceTTL: getDuration("NONCE_TTL", 60*time.Second),
TimestampWindow: getDuration("TIMESTAMP_WINDOW", 30*time.Second),
LogLevel: getEnv("LOG_LEVEL", "info"),
}
}
func getEnv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}
func getDuration(key string, fallback time.Duration) time.Duration {
if v := os.Getenv(key); v != "" {
d, err := time.ParseDuration(v)
if err == nil {
return d
}
}
return fallback
}