Compare commits
3 Commits
ccd2c530cf
...
793a3d460a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
793a3d460a | ||
|
|
b107b88800 | ||
|
|
d562558a3e |
4
trunk/.idea/trunk.iml
Normal file
4
trunk/.idea/trunk.iml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
</module>
|
||||
6
trunk/.idea/vcs.xml
Normal file
6
trunk/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -4,7 +4,10 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="2037df1b-9ccc-4caa-9145-2d6722712612" name="更改" comment="" />
|
||||
<list default="true" id="2037df1b-9ccc-4caa-9145-2d6722712612" name="更改" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/center/usercenter/internal/user/logic.go" beforeDir="false" afterPath="$PROJECT_DIR$/center/usercenter/internal/user/logic.go" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@ -19,8 +22,12 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="GOROOT" url="file://$USER_HOME$/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.windows-amd64" />
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
||||
</component>
|
||||
<component name="HighlightingSettingsPerFile">
|
||||
<setting file="file://$USER_HOME$/go/pkg/mod/github.com/wechatpay-apiv3/wechatpay-go@v0.2.20/services/payments/jsapi/api_jsapi_request_payment.go" root0="SKIP_INSPECTION" />
|
||||
<setting file="file://$USER_HOME$/go/pkg/mod/github.com/wechatpay-apiv3/wechatpay-go@v0.2.20/services/payments/native/models.go" root0="SKIP_INSPECTION" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 3
|
||||
@ -37,17 +44,19 @@
|
||||
"Docker.center/admincenter/Dockerfile builder.executor": "Run",
|
||||
"Go 构建.go build admincenter.executor": "Debug",
|
||||
"Go 构建.go build logincenter.executor": "Debug",
|
||||
"Go 构建.go build usercenter.executor": "Debug",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"go.import.settings.migrated": "true",
|
||||
"go.sdk.automatically.set": "true",
|
||||
"last_opened_file_path": "D:/desktop/go_test01",
|
||||
"last_opened_file_path": "D:/workspace/e2023/goProject/trunk",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"settings.editor.selected.configurable": "go.sdk"
|
||||
"settings.editor.selected.configurable": "preferences.pluginManager"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
@ -57,7 +66,7 @@
|
||||
<recent name="D:\workspace\e2023\goProject\trunk\center" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager" selected="Go 构建.go build logincenter">
|
||||
<component name="RunManager" selected="Go 构建.go build usercenter">
|
||||
<configuration name="go build admincenter" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
||||
<module name="trunk" />
|
||||
<working_directory value="$PROJECT_DIR$/center/admincenter" />
|
||||
@ -67,9 +76,9 @@
|
||||
<filePath value="$PROJECT_DIR$/center/admincenter/main.go" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="go build logincenter" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
||||
<configuration name="go build usercenter" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
|
||||
<module name="trunk" />
|
||||
<working_directory value="$PROJECT_DIR$/center/logincenter" />
|
||||
<working_directory value="$PROJECT_DIR$/center/usercenter" />
|
||||
<kind value="PACKAGE" />
|
||||
<package value="logincenter" />
|
||||
<directory value="$PROJECT_DIR$" />
|
||||
@ -113,7 +122,7 @@
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Go 构建.go build logincenter" />
|
||||
<item itemvalue="Go 构建.go build usercenter" />
|
||||
<item itemvalue="Go 构建.go build admincenter" />
|
||||
<item itemvalue="Docker.admincenter.redis: Compose 部署" />
|
||||
<item itemvalue="Docker.center/admincenter/Dockerfile builder" />
|
||||
@ -143,6 +152,11 @@
|
||||
<line>68</line>
|
||||
<option name="timeStamp" value="8" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/center/usercenter/internal/user/logic.go</url>
|
||||
<line>104</line>
|
||||
<option name="timeStamp" value="23" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
</breakpoint-manager>
|
||||
</component>
|
||||
|
||||
@ -33,6 +33,7 @@ type AdminApi struct {
|
||||
func init() {
|
||||
moduleName := "AdminApi"
|
||||
methodName := "Add"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "添加管理员用户"
|
||||
methodAuthor := "tangping"
|
||||
methodMendor := ""
|
||||
@ -47,7 +48,7 @@ func init() {
|
||||
"id '类型:int'": "管理员id",
|
||||
}
|
||||
}`
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam)
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
func (a *AdminApi) Add(account string, name string, password string, sex int32, birthday string, phone int64, email string, wechatGroup string, describe string) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
@ -86,6 +87,7 @@ func (a *AdminApi) Add(account string, name string, password string, sex int32,
|
||||
func init() {
|
||||
moduleName := "AdminApi"
|
||||
methodName := "Get"
|
||||
skipVerifyTokenPage := false
|
||||
methodDesc := "获取管理员用户"
|
||||
methodAuthor := "tangping"
|
||||
methodMendor := ""
|
||||
@ -108,12 +110,14 @@ func init() {
|
||||
}
|
||||
}`
|
||||
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam)
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
func (a *AdminApi) Get(adminId int64) (responseObj *webServer.ResponseObject) {
|
||||
func (a *AdminApi) Get(useAdmin *Admin, adminId int64) (responseObj *webServer.ResponseObject) {
|
||||
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
|
||||
//获取当前登录用户信息
|
||||
|
||||
//验证参数
|
||||
if adminId == 0 {
|
||||
responseObj.SetResultStatus(resultStatus.APIDataError)
|
||||
@ -145,6 +149,7 @@ func (a *AdminApi) Get(adminId int64) (responseObj *webServer.ResponseObject) {
|
||||
func init() {
|
||||
moduleName := "AdminApi"
|
||||
methodName := "Login"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "管理员登录"
|
||||
methodAuthor := "tangping"
|
||||
methodMendor := ""
|
||||
@ -160,7 +165,7 @@ func init() {
|
||||
}
|
||||
}`
|
||||
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam)
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
|
||||
func (a *AdminApi) Login(account string, password string) (responseObj *webServer.ResponseObject) {
|
||||
@ -187,7 +192,7 @@ func (a *AdminApi) Login(account string, password string) (responseObj *webServe
|
||||
}
|
||||
|
||||
//添加登录用户
|
||||
webServer.AddLoginUserToken(token, &webServer.TokenInfo{Id: adminData.ID, Account: account})
|
||||
webServer.AddLoginUserToken(token, &webServer.TokenInfo{Id: adminData.ID, Account: account, UserInfo: adminData})
|
||||
|
||||
//adminData映射成map
|
||||
resultMap := make(map[string]any)
|
||||
|
||||
@ -35,6 +35,9 @@ func main() {
|
||||
// 目前函数的实现为空,需要根据实际的配置加载逻辑进行填充。
|
||||
func loadConfig() {
|
||||
|
||||
//设置数据类型
|
||||
connection.SetModelDB(connection.GetAdminDB())
|
||||
|
||||
//构建数据库
|
||||
connection.BuildDB()
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package remark
|
||||
|
||||
import (
|
||||
"common/webServer"
|
||||
"goutil/logUtilPlus"
|
||||
)
|
||||
|
||||
@ -41,7 +42,7 @@ func RegisterModuleRemark(name, desc, author, mendor, date string) {
|
||||
// @outParam: 输出参数
|
||||
//
|
||||
// return:
|
||||
func RegisterMethodRemark(moduleName, name, desc, author, mendor, date string, inParam []string, outParam string) {
|
||||
func RegisterMethodRemark(moduleName, name, desc, author, mendor, date string, inParam []string, outParam string, skipVerifyTokenPage bool) {
|
||||
var moduleRemark *ModuleRemark
|
||||
var exists bool
|
||||
for _, item := range remarksSlice {
|
||||
@ -57,4 +58,9 @@ func RegisterMethodRemark(moduleName, name, desc, author, mendor, date string, i
|
||||
}
|
||||
|
||||
moduleRemark.MethodRemarkSlice = append(moduleRemark.MethodRemarkSlice, newMethodRemark(moduleName, name, desc, author, mendor, date, inParam, outParam))
|
||||
|
||||
//跳过登录验证
|
||||
if skipVerifyTokenPage {
|
||||
webServer.AddSkipVerifyTokenPage(moduleName, name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -387,6 +387,11 @@ func CallFunction(requestObj *RequestObject) (responseObj *ResponseObject) {
|
||||
in[i] = reflect.ValueOf(param_uint8)
|
||||
}
|
||||
}
|
||||
case reflect.Pointer:
|
||||
//if paramStruct, ok := paramItem.(struct{}); ok {
|
||||
// in[i] = reflect.ValueOf(paramStruct)
|
||||
//}
|
||||
in[i] = reflect.ValueOf(paramItem)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -91,24 +91,28 @@ func (mux *selfDefineMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
params, err = context.RequestDataBySlice2ByJson()
|
||||
if err != nil {
|
||||
responseResult(w, responseObj.SetResultStatus(resultStatus.APIDataError))
|
||||
return
|
||||
}
|
||||
|
||||
//验证是否登录
|
||||
if strs[0] != "AdminApi" || strs[1] != "Login" {
|
||||
if !IsSkipVerifyTokenPage(strs[0], strs[1]) {
|
||||
tokenStr := context.header.Get("token")
|
||||
|
||||
// token 转型成 int64
|
||||
token := stringUtil.StringToInt64(tokenStr)
|
||||
|
||||
//是否存在
|
||||
if !CheckToken(token) {
|
||||
exist, tokenData := CheckToken(token)
|
||||
if !exist {
|
||||
responseResult(w, responseObj.SetResultStatus(resultStatus.NotLogin))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
params, err = context.RequestDataBySlice2ByJson()
|
||||
if err != nil {
|
||||
responseResult(w, responseObj.SetResultStatus(resultStatus.APIDataError))
|
||||
return
|
||||
//添加登录用户到参数里的第一个
|
||||
params = append([]interface{}{tokenData.UserInfo}, params...)
|
||||
}
|
||||
|
||||
resquestData := NewRequestObject(strs[0], strs[1], params)
|
||||
|
||||
@ -11,6 +11,9 @@ var (
|
||||
|
||||
//锁
|
||||
lock sync.RWMutex
|
||||
|
||||
//跳过验证token的页面
|
||||
skipVerifyTokenPage = make(map[string]bool)
|
||||
)
|
||||
|
||||
type TokenInfo struct {
|
||||
@ -20,6 +23,9 @@ type TokenInfo struct {
|
||||
//管理员账号
|
||||
Account string
|
||||
|
||||
//登录用户缓存
|
||||
UserInfo any
|
||||
|
||||
//过期时间
|
||||
ExpireTime time.Time
|
||||
}
|
||||
@ -57,7 +63,7 @@ func AddLoginUserToken(token int64, tokenInfo *TokenInfo) {
|
||||
// 返回值:
|
||||
//
|
||||
// bool: 表示令牌是否有效的布尔值,true表示有效,false表示无效
|
||||
func CheckToken(token int64) bool {
|
||||
func CheckToken(token int64) (bool, *TokenInfo) {
|
||||
|
||||
//添加锁防止并发
|
||||
lock.Lock()
|
||||
@ -70,7 +76,7 @@ func CheckToken(token int64) bool {
|
||||
tokenInfo, ok := loginUserMap[token]
|
||||
if !ok {
|
||||
// 如果没有找到对应的用户信息,则令牌无效
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 获取令牌过期时间
|
||||
@ -82,11 +88,23 @@ func CheckToken(token int64) bool {
|
||||
//移除令牌
|
||||
delete(loginUserMap, token)
|
||||
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
|
||||
//如果生效的话,则更新过期时间
|
||||
tokenInfo.ExpireTime = now.Add(time.Hour * 24)
|
||||
|
||||
return true
|
||||
return true, tokenInfo
|
||||
}
|
||||
|
||||
func AddSkipVerifyTokenPage(moduleName, methodName string) {
|
||||
skipVerifyTokenPage[moduleName+"_"+methodName] = true
|
||||
}
|
||||
|
||||
func IsSkipVerifyTokenPage(moduleName, methodName string) bool {
|
||||
exist, ok := skipVerifyTokenPage[moduleName+"_"+methodName]
|
||||
if !exist {
|
||||
return false
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
69
trunk/center/usercenter/internal/game/api.go
Normal file
69
trunk/center/usercenter/internal/game/api.go
Normal file
@ -0,0 +1,69 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"common/remark"
|
||||
"common/resultStatus"
|
||||
"common/webServer"
|
||||
"logincenter/internal/user"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
//注册接口
|
||||
webServer.RegisterFunction(new(GameApi))
|
||||
}
|
||||
|
||||
func init() {
|
||||
moduleName := "GameApi"
|
||||
desc := "用户接口"
|
||||
author := "tangping"
|
||||
mendor := ""
|
||||
date := "2025年1月7日14:38:22"
|
||||
remark.RegisterModuleRemark(moduleName, desc, author, mendor, date)
|
||||
}
|
||||
|
||||
// GameApi 游戏接口
|
||||
type GameApi struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
moduleName := "GameApi"
|
||||
methodName := "Add"
|
||||
skipVerifyTokenPage := false
|
||||
methodDesc := "添加游戏"
|
||||
methodAuthor := "tangping"
|
||||
methodMendor := ""
|
||||
methodDate := "2024-12-25 15:55:00"
|
||||
methodInParam := []string{"string 账号,int 游戏id"}
|
||||
methodOutParam := `
|
||||
{
|
||||
"Code '类型:int'": "响应结果的状态值",
|
||||
"Message '类型:string'": "响应结果的状态值所对应的描述信息",
|
||||
"Data '类型:interface{}'": "响应结果的数据"
|
||||
{
|
||||
|
||||
}
|
||||
}`
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
|
||||
func (this *GameApi) Add(userData *user.User, account string, gameId int64) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
|
||||
//用户登录用户数据
|
||||
|
||||
//参数验证
|
||||
|
||||
//添加游戏
|
||||
game := &Game{
|
||||
Account: account,
|
||||
GameID: int64(gameId),
|
||||
}
|
||||
|
||||
gameId, err := AddGame(userData, game)
|
||||
if err != nil {
|
||||
return responseObj.SetResultStatus(resultStatus.DataError)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@ -33,6 +33,7 @@ type UserApi struct {
|
||||
func init() {
|
||||
moduleName := "UserApi"
|
||||
methodName := "Register"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "注册用户"
|
||||
methodAuthor := "tangping"
|
||||
methodMendor := ""
|
||||
@ -47,7 +48,7 @@ func init() {
|
||||
"id '类型:int'": "用户id",
|
||||
}
|
||||
}`
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam)
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
func (a *UserApi) Register(account string, name string, password string, sex int32, birthday string, phone int64, email string, wechatGroup string, describe string) (responseObj *webServer.ResponseObject) {
|
||||
responseObj = webServer.GetInitResponseObj()
|
||||
@ -86,6 +87,7 @@ func (a *UserApi) Register(account string, name string, password string, sex int
|
||||
func init() {
|
||||
moduleName := "UserApi"
|
||||
methodName := "Login"
|
||||
skipVerifyTokenPage := true
|
||||
methodDesc := "用户登录"
|
||||
methodAuthor := "tangping"
|
||||
methodMendor := ""
|
||||
@ -101,7 +103,7 @@ func init() {
|
||||
}
|
||||
}`
|
||||
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam)
|
||||
remark.RegisterMethodRemark(moduleName, methodName, methodDesc, methodAuthor, methodMendor, methodDate, methodInParam, methodOutParam, skipVerifyTokenPage)
|
||||
}
|
||||
|
||||
func (a *UserApi) Login(account string, password string) (responseObj *webServer.ResponseObject) {
|
||||
@ -128,7 +130,7 @@ func (a *UserApi) Login(account string, password string) (responseObj *webServer
|
||||
}
|
||||
|
||||
//添加登录用户
|
||||
webServer.AddLoginUserToken(token, &webServer.TokenInfo{Id: userData.ID, Account: account})
|
||||
webServer.AddLoginUserToken(token, &webServer.TokenInfo{Id: userData.ID, Account: account, UserInfo: userData})
|
||||
|
||||
//UserData映射成map
|
||||
resultMap := make(map[string]any)
|
||||
|
||||
@ -7,9 +7,13 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
// 用户缓存对象
|
||||
var userMap = make(map[int64]*User)
|
||||
var rwmu sync.RWMutex
|
||||
userMap = make(map[int64]*User)
|
||||
rwmu sync.RWMutex
|
||||
userAccountMap = make(map[string]*User)
|
||||
rwmu2 sync.RWMutex
|
||||
)
|
||||
|
||||
// GetUserByID 根据用户id获取用户信息
|
||||
func GetUserByID(UserID int64) (*User, error) {
|
||||
@ -55,35 +59,61 @@ func AddUserCache(user *User) {
|
||||
userMap[user.ID] = user
|
||||
}
|
||||
|
||||
func GetUserByAccount(account string) (*User, error) {
|
||||
rwmu2.RLock()
|
||||
defer rwmu2.RUnlock()
|
||||
|
||||
//判断缓存是否存在
|
||||
var user *User
|
||||
ok := true
|
||||
if user, ok = userAccountMap[account]; ok {
|
||||
return user, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func AddUserIdCache(user *User) {
|
||||
rwmu2.Lock()
|
||||
defer rwmu2.Unlock()
|
||||
user.Cache = cache.NewCache()
|
||||
userAccountMap[user.Account] = user
|
||||
}
|
||||
|
||||
// AddUser 添加用户
|
||||
// AddUser 添加新的用户到数据库中。
|
||||
// 参数 User: 包含用户信息的对象。
|
||||
// 返回值: 插入操作影响的行数和可能发生的错误。
|
||||
func AddUser(User *User) (int64, error) {
|
||||
func AddUser(user *User) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
//写入缓存
|
||||
AddUserCache(User)
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Create(&User) // 通过数据的指针来创建
|
||||
|
||||
result := connection.GetUserDB().Create(&user) // 通过数据的指针来创建
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("添加用户失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
return User.ID, nil
|
||||
|
||||
return user.ID, nil
|
||||
}
|
||||
|
||||
// Login 用户登录
|
||||
func Login(account string, password string) (*User, error) {
|
||||
|
||||
//这里优先验证缓存数据
|
||||
var user *User
|
||||
|
||||
var User User
|
||||
result := connection.GetUserDB().Where("account = ? AND password = ?", account, password).First(&User)
|
||||
//这里优先验证缓存数据
|
||||
user, err := GetUserByAccount(account)
|
||||
if err == nil && user != nil {
|
||||
return user, err
|
||||
}
|
||||
result := connection.GetUserDB().Where("account = ? AND password = ?", account, password).First(&user)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
return &User, nil
|
||||
|
||||
//写入缓存
|
||||
AddUserCache(user)
|
||||
AddUserIdCache(user)
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user