feat: 0.1.2

1. login page && auth required
  2. file dir cleanup
This commit is contained in:
loveuer
2025-05-09 17:49:12 +08:00
parent a2635698e0
commit b1b3ac5b6b
31 changed files with 1178 additions and 36 deletions

51
internal/pkg/db/client.go Normal file
View File

@ -0,0 +1,51 @@
package db
import (
"au99999/internal/opt"
"au99999/pkg/tool"
"context"
"gorm.io/gorm"
)
var Default *Client
type DBType string
const (
DBTypeSqlite = "sqlite"
DBTypeMysql = "mysql"
DBTypePostgres = "postgres"
)
type Client struct {
ctx context.Context
cli *gorm.DB
dbType DBType
}
func (c *Client) Type() DBType {
return c.dbType
}
func (c *Client) Session(ctxs ...context.Context) *gorm.DB {
var ctx context.Context
if len(ctxs) > 0 && ctxs[0] != nil {
ctx = ctxs[0]
} else {
ctx = tool.Timeout(30)
}
session := c.cli.Session(&gorm.Session{Context: ctx})
if opt.Cfg.Debug {
session = session.Debug()
}
return session
}
func (c *Client) Close() {
d, _ := c.cli.DB()
d.Close()
}