feat: Phase 1 — 项目骨架搭建,集成 Gin、SQLite 和设置页面

This commit is contained in:
2026-06-18 22:48:16 +08:00
parent 46f1bbf0f1
commit 1e9b1a2129
26 changed files with 2518 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package config
import (
"os"
"path/filepath"
)
type Config struct {
Port string
GinMode string
DataDir string
}
func Load() *Config {
cfg := &Config{
Port: getEnv("PORT", "8080"),
GinMode: getEnv("GIN_MODE", "debug"),
DataDir: getEnv("DATA_DIR", "data"),
}
// Ensure data directories exist
os.MkdirAll(cfg.DataDir, 0o755)
os.MkdirAll(filepath.Join(cfg.DataDir, "repos"), 0o755)
return cfg
}
func (c *Config) DBPath() string {
return filepath.Join(c.DataDir, "pr-helper.db")
}
func (c *Config) ReposDir() string {
return filepath.Join(c.DataDir, "repos")
}
func getEnv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}