主要改进: - 重构用户信息卡片,新增统计数据展示区域 - 统一题型卡片图标样式,添加渐变背景容器 - 优化快速开始卡片的图标设计 - 调整配色方案为明快风格,提升视觉效果 - 修改题型图标:判断题使用CloseCircleOutlined,填空题使用FormOutlined,论述题使用FileMarkdownOutlined - 完善响应式设计,优化移动端和PC端显示效果 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
// DatabaseConfig 数据库配置结构
|
|
type DatabaseConfig struct {
|
|
Host string
|
|
Port int
|
|
User string
|
|
Password string
|
|
DBName string
|
|
SSLMode string
|
|
}
|
|
|
|
// AIConfig AI服务配置结构
|
|
type AIConfig struct {
|
|
BaseURL string
|
|
APIKey string
|
|
Model string
|
|
}
|
|
|
|
// GetDatabaseConfig 获取数据库配置
|
|
// 优先使用环境变量,如果没有设置则使用默认值
|
|
func GetDatabaseConfig() *DatabaseConfig {
|
|
// 从环境变量获取配置,如果未设置则使用默认值
|
|
host := getEnv("DB_HOST", "pgsql.yuchat.top")
|
|
port := getEnvAsInt("DB_PORT", 5432)
|
|
user := getEnv("DB_USER", "postgres")
|
|
password := getEnv("DB_PASSWORD", "longqi@1314")
|
|
dbname := getEnv("DB_NAME", "ankao")
|
|
sslmode := getEnv("DB_SSLMODE", "disable")
|
|
|
|
return &DatabaseConfig{
|
|
Host: host,
|
|
Port: port,
|
|
User: user,
|
|
Password: password,
|
|
DBName: dbname,
|
|
SSLMode: sslmode,
|
|
}
|
|
}
|
|
|
|
// getEnv 获取环境变量,如果不存在则返回默认值
|
|
func getEnv(key, defaultValue string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
// getEnvAsInt 获取整型环境变量,如果不存在或转换失败则返回默认值
|
|
func getEnvAsInt(key string, defaultValue int) int {
|
|
if value := os.Getenv(key); value != "" {
|
|
if intValue, err := strconv.Atoi(value); err == nil {
|
|
return intValue
|
|
}
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
// GetDSN 返回数据库连接字符串
|
|
func (c *DatabaseConfig) GetDSN() string {
|
|
return fmt.Sprintf(
|
|
"host=%s user=%s password=%s dbname=%s port=%d sslmode=%s",
|
|
c.Host,
|
|
c.User,
|
|
c.Password,
|
|
c.DBName,
|
|
c.Port,
|
|
c.SSLMode,
|
|
)
|
|
}
|
|
|
|
// GetAIConfig 获取AI服务配置
|
|
// 优先使用环境变量,如果没有设置则使用默认值
|
|
func GetAIConfig() *AIConfig {
|
|
baseURL := getEnv("AI_BASE_URL", "http://172.20.0.117")
|
|
apiKey := getEnv("AI_API_KEY", "sk-OKBmOpJx855juSOPU14cWG6Iz87tZQuv3Xg9PiaJYXdHoKcN")
|
|
model := getEnv("AI_MODEL", "deepseek-v3")
|
|
|
|
return &AIConfig{
|
|
BaseURL: baseURL,
|
|
APIKey: apiKey,
|
|
Model: model,
|
|
}
|
|
}
|