DI&GIN验证尝试

DI 框架我是没招了,GO 的狗屎接口系统让运行时的DI注入都没办法自动收集接口。
所以...只能捏着鼻子用了。正在想办法解决 GIN 验证框架返回英文的问题
This commit is contained in:
des
2026-01-23 00:02:13 +08:00
parent 688177ba06
commit 731f1d01e6
12 changed files with 157 additions and 132 deletions

View File

@@ -2,6 +2,7 @@ package database
import (
"Crimson-Gatekeeper/internal/query"
"database/sql"
"fmt"
"gorm.io/driver/postgres"
@@ -13,7 +14,7 @@ import (
// 返回值
// - 一个 gorm.DB 的指针
// - 一个清理所有数据库相关数据的函数
func GetDataBaseClient() *gorm.DB {
func GetDataBaseClient() (*gorm.DB, error) {
dsn := "host=localhost " +
"user=gatekeeper " +
"dbname=crimson " +
@@ -25,27 +26,21 @@ func GetDataBaseClient() *gorm.DB {
client, ero := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if ero != nil {
fmt.Println("数据库链接建立失败")
panic(ero)
return nil, ero
}
poolCfg, ero := client.DB()
if ero != nil {
return client, nil
}
func GetPoolCfg(g *gorm.DB) (*sql.DB, error) {
pool, err := g.DB()
if err != nil {
fmt.Println("获取数据库链接池失败")
panic(ero)
return nil, err
}
//cleanPoolCfg := func() {
// ero := poolCfg.Close()
// if ero != nil {
// fmt.Println("清理过程中出现错误")
// panic(ero)
// }
//}
poolCfg.SetConnMaxIdleTime(3)
poolCfg.SetMaxOpenConns(10)
return client
pool.SetConnMaxIdleTime(3)
pool.SetMaxOpenConns(10)
return pool, nil
}
func GetQuery(db *gorm.DB) *query.Query {