Files
Cyrene/backend/memory-service/internal/config/config.go
T
AskaEth 8bbde1c1d7 fix: 统一数据库默认密码 change_me → cyrene_pass
Docker Compose 和 .env 使用 cyrene_pass,但 5 个 Go 源码文件
和 DevTools config.js 中的 fallback 密码仍是 change_me,
导致 memory-service/tool-engine/gateway 启动后 DB 认证失败。
修复 7 个文件中的硬编码 fallback 密码,统一为 cyrene_pass。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 21:27:56 +08:00

46 lines
996 B
Go

package config
import (
"fmt"
"os"
)
// Config 记忆服务配置
type Config struct {
Port string
DatabaseURL string
}
// Load 从环境变量加载配置
func Load() *Config {
return &Config{
Port: getEnv("PORT", "8091"),
DatabaseURL: buildDatabaseURL(),
}
}
// buildDatabaseURL 构建 PostgreSQL 连接字符串
func buildDatabaseURL() string {
// 优先使用 DB_URL 环境变量(简化模式)
if url := os.Getenv("DB_URL"); url != "" {
return url
}
host := getEnv("POSTGRES_HOST", "localhost")
port := getEnv("POSTGRES_PORT", "5432")
user := getEnv("POSTGRES_USER", "cyrene")
password := getEnv("POSTGRES_PASSWORD", "cyrene_pass")
dbname := getEnv("POSTGRES_DB", "cyrene_ai")
sslmode := getEnv("POSTGRES_SSLMODE", "disable")
return fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s",
user, password, host, port, dbname, sslmode)
}
func getEnv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}