wip: 登录和认证

This commit is contained in:
loveuer
2025-07-13 22:57:57 +08:00
parent 48af538f98
commit b48fa05d9f
33 changed files with 1961 additions and 33 deletions

49
pkg/database/db/db.go Normal file
View File

@ -0,0 +1,49 @@
package db
import (
"context"
"gorm.io/gorm"
)
type Config struct {
Debug bool
DryRun bool
}
type DB interface {
Session(ctx context.Context, configs ...Config) *gorm.DB
}
type db struct {
tx *gorm.DB
}
var (
Default DB
)
func (db *db) Session(ctx context.Context, configs ...Config) *gorm.DB {
var (
sc = &gorm.Session{Context: ctx}
session *gorm.DB
)
if len(configs) == 0 {
session = db.tx.Session(sc)
return session
}
cfg := configs[0]
if cfg.DryRun {
sc.DryRun = true
}
session = db.tx.Session(sc)
if cfg.Debug {
session = session.Debug()
}
return session
}