主要改动: - 集成 GORM 和 PostgreSQL 驱动 - 创建数据库配置模块 (pkg/config) - 实现数据库连接和初始化 (internal/database) - 更新用户模型支持 GORM 和 bcrypt 密码加密 - 重构用户注册和登录处理器使用数据库存储 - 删除旧的 users.json 文件存储方式 - 更新 README.md 和 CLAUDE.md 文档 技术栈: - GORM v1.31.1 - ORM框架 - PostgreSQL - 数据库 - bcrypt - 密码加密 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
41 lines
709 B
Go
41 lines
709 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// DatabaseConfig 数据库配置结构
|
|
type DatabaseConfig struct {
|
|
Host string
|
|
Port int
|
|
User string
|
|
Password string
|
|
DBName string
|
|
SSLMode string
|
|
}
|
|
|
|
// GetDatabaseConfig 获取数据库配置
|
|
func GetDatabaseConfig() *DatabaseConfig {
|
|
return &DatabaseConfig{
|
|
Host: "pgsql.yuchat.top",
|
|
Port: 5432,
|
|
User: "postgres",
|
|
Password: "longqi@1314",
|
|
DBName: "ankao",
|
|
SSLMode: "disable",
|
|
}
|
|
}
|
|
|
|
// 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,
|
|
)
|
|
}
|