部分更改

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

@@ -22,6 +22,7 @@ require (
github.com/goccy/go-json v0.10.2 // indirect github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect github.com/goccy/go-yaml v1.18.0 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/google/wire v0.7.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.8.0 // indirect github.com/jackc/pgx/v5 v5.8.0 // indirect

View File

@@ -34,6 +34,8 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/wire v0.7.0 h1:JxUKI6+CVBgCO2WToKy/nQk0sS+amI9z9EjVmdaocj4=
github.com/google/wire v0.7.0/go.mod h1:n6YbUQD9cPKTnHXEBN2DXlOp/mVADhVErcMFb0v3J18=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=

View File

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

View File

@@ -0,0 +1,13 @@
package wire_generate
import (
"Crimson-Gatekeeper/internal/common"
"Crimson-Gatekeeper/internal/user"
"github.com/google/wire"
)
func TestInit() *user.Controller {
wire.Build(user.New, common.GetQuery, common.GetDataBaseClient)
return &user.Controller{}
}