Files
cc-hook/config.go
T
wonder 075a8bf40b feat: 引入 godotenv 管理环境变量,优化 Dockerfile 构建
- 新增 .env.example 和 .gitignore
- config.go 使用 godotenv 加载 .env,移除硬编码凭据
- docker-compose.yml 改用 env_file 引用 .env
- Dockerfile 使用国内镜像源 + 缓存加速构建
- README.md Hook URL 改为服务器地址,配置说明更新
2026-06-21 22:01:38 +08:00

34 lines
529 B
Go

package main
import (
"os"
"github.com/joho/godotenv"
)
func init() {
// 加载 .env 文件(如果存在),环境变量优先
_ = godotenv.Load()
}
type Config struct {
GotifyURL string
GotifyToken string
Port string
}
func LoadConfig() Config {
return Config{
GotifyURL: getEnv("GOTIFY_URL", ""),
GotifyToken: getEnv("GOTIFY_TOKEN", ""),
Port: getEnv("PORT", ":8082"),
}
}
func getEnv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}