部分更改
This commit is contained in:
@@ -22,6 +22,7 @@ require (
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/goccy/go-yaml v1.18.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/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/pgx/v5 v5.8.0 // indirect
|
||||
|
||||
@@ -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/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/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/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
25
srv/internal/user/login_manage.go
Normal file
25
srv/internal/user/login_manage.go
Normal 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{}}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
13
srv/tools/wire_generate/wire.go
Normal file
13
srv/tools/wire_generate/wire.go
Normal 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{}
|
||||
}
|
||||
Reference in New Issue
Block a user