部分更改

This commit is contained in:
des
2026-01-20 00:18:05 +08:00
parent 2d65afdf33
commit 1ab62031ea
6 changed files with 59 additions and 20 deletions

View File

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

View File

@@ -0,0 +1,25 @@
package user
import (
"Crimson-Gatekeeper/internal/model"
"sync"
"time"
)
type login_info struct {
info model.User
token string
invalidation time.Time
}
type login_manage struct {
data *sync.Map
}
func (l *login_manage) Login(li *login_info) {
l.data.Store(li.token, li)
}
func newLoginManage() *login_manage {
return &login_manage{data: &sync.Map{}}
}

View File

@@ -1,25 +1,9 @@
package user
import (
"Crimson-Gatekeeper/internal/model"
"Crimson-Gatekeeper/internal/query"
"sync"
"time"
)
// loginInfo 储存用户的登录状态
type loginInfo struct {
// user 信息指针
user *model.User
// invalidation 失效时间,此事件之后,该数据应该失效且被删除
invalidation time.Time
}
var loginIn = sync.Map{}
type Service struct {
c *query.Query
}
func (s *Service) login(user *model.User) error {
}