9c843b79ba
- 新增 users 和 user_settings 表,repositories/analyses/review_notes 添加 user_id 列 - 实现基于邮箱+密码的注册登录,密码使用 bcrypt 哈希 - 使用 gin-contrib/sessions cookie-based session 管理 - 所有仓库、分析记录、review notes 按用户隔离 - 用户设置(LLM 配置、review 参数、缓存配置)独立存储 - 新增登录/注册页面,导航栏显示用户邮箱和退出按钮 - 前端 fetch 请求统一添加 credentials: 'same-origin' - 支持 SESSION_SECRET 环境变量配置会话密钥
50 lines
1001 B
Go
50 lines
1001 B
Go
package config
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
GinMode string
|
|
DataDir string
|
|
SessionSecret string
|
|
}
|
|
|
|
func Load() *Config {
|
|
cfg := &Config{
|
|
Port: getEnv("PORT", "8080"),
|
|
GinMode: getEnv("GIN_MODE", "debug"),
|
|
DataDir: getEnv("DATA_DIR", "data"),
|
|
SessionSecret: getEnv("SESSION_SECRET", ""),
|
|
}
|
|
// Generate random session secret if not provided
|
|
if cfg.SessionSecret == "" {
|
|
b := make([]byte, 32)
|
|
rand.Read(b)
|
|
cfg.SessionSecret = hex.EncodeToString(b)
|
|
}
|
|
// 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
|
|
}
|