Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package qcloud
|
||||
|
||||
type telField struct {
|
||||
Nationcode string `json:"nationcode"`
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
|
||||
func newTelField(nation, mobile string) *telField {
|
||||
return &telField{
|
||||
Nationcode: nation,
|
||||
Mobile: mobile,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package gameServerMgr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"Framework/goroutineMgr"
|
||||
. "Framework/managecenterModel"
|
||||
"goutil/logUtil"
|
||||
"goutil/webUtil"
|
||||
)
|
||||
|
||||
const SYSCONF_URL_SUFFIX string = "/API/SysConfig.ashx"
|
||||
|
||||
var (
|
||||
mSysConfig *SysConfig
|
||||
)
|
||||
|
||||
// 获取MC系统配置
|
||||
func GetSysConfigFromManageCenterServer() error {
|
||||
//定义参数
|
||||
requestParamMap := make(map[string]string, 0)
|
||||
requestParamMap["IsResultCompressed"] = "false"
|
||||
|
||||
//构造url
|
||||
url := fmt.Sprintf("%s/%s", mManageCenterServerAPIUrl, SYSCONF_URL_SUFFIX)
|
||||
|
||||
//请求url,请求头
|
||||
header := webUtil.GetFormHeader()
|
||||
transport := webUtil.NewTransport()
|
||||
transport.DisableKeepAlives = true
|
||||
transport = webUtil.GetTimeoutTransport(transport, 30)
|
||||
|
||||
statusCode, returnBytes, err := webUtil.PostMapData(url, requestParamMap, header, transport)
|
||||
//statusCode, returnBytes, err := webUtil.PostMapData(url, requestParamMap, header, nil)
|
||||
if err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取MC系统配置出错,url:%s,错误信息为:%s", url, err))
|
||||
return err
|
||||
}
|
||||
if statusCode != 200 {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取MC系统配置出错,url:%s,错误码为:%d", url, statusCode))
|
||||
return err
|
||||
}
|
||||
// 解析返回值
|
||||
returnObj := new(ReturnObject)
|
||||
if err = json.Unmarshal(returnBytes, &returnObj); err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取MC系统配置出错,反序列化返回值出错,错误信息为:%s, str:%s", err, string(returnBytes)))
|
||||
return err
|
||||
}
|
||||
|
||||
// 判断返回状态是否为成功
|
||||
if returnObj.Code != 0 {
|
||||
// 数据没有变化,所以没有获取到新的数据,不能算错误。
|
||||
if returnObj.Code == 47 || returnObj.Message == "DataNotChanged" {
|
||||
return nil
|
||||
} else {
|
||||
msg := fmt.Sprintf("获取MC系统配置出错,返回状态:%d,信息为:%s", returnObj.Code, returnObj.Message)
|
||||
logUtil.ErrorLog(msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// 解析Data
|
||||
var tmpSysConfig *SysConfig
|
||||
if data, ok := returnObj.Data.(string); !ok {
|
||||
msg := "获取MC系统配置出错,返回的数据不是string类型"
|
||||
logUtil.ErrorLog(msg)
|
||||
return errors.New(msg)
|
||||
} else {
|
||||
if err = json.Unmarshal([]byte(data), &tmpSysConfig); err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("获取MC系统配置出错出错,反序列化数据出错,错误信息为:%s", err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 赋值给最终的sysconfig
|
||||
mSysConfig = tmpSysConfig
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 定时刷新MC系统配置
|
||||
func StartRefreshSysConfigTread() {
|
||||
// 定时刷新数据
|
||||
go func() {
|
||||
goroutineName := "gameServerMgr.StartRefreshSysConfigTread"
|
||||
goroutineMgr.Monitor(goroutineName)
|
||||
defer goroutineMgr.ReleaseMonitor(goroutineName)
|
||||
|
||||
for {
|
||||
// 每30秒刷新一次
|
||||
time.Sleep(30 * time.Second)
|
||||
|
||||
// MC系统配置
|
||||
GetSysConfigFromManageCenterServer()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// 获取系统配置
|
||||
func GetSysConfig() *SysConfig {
|
||||
return mSysConfig
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package initMgr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRegister(t *testing.T) {
|
||||
Register("first", 1, first)
|
||||
Register("second", 2, second)
|
||||
Register("third", 3, third)
|
||||
Register("fourth", 4, fourth)
|
||||
}
|
||||
|
||||
func TestCallOne(t *testing.T) {
|
||||
name := "first"
|
||||
if err := CallOne(name); err != nil {
|
||||
t.Errorf("there should be no error, but now it has:%s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallAny(t *testing.T) {
|
||||
errList := CallAny("second", "third")
|
||||
if len(errList) != 1 {
|
||||
t.Errorf("there should be 1 error, but now:%d", len(errList))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallAll(t *testing.T) {
|
||||
errList := CallAll()
|
||||
if len(errList) != 2 {
|
||||
t.Errorf("there should be 1 error, but now:%d", len(errList))
|
||||
}
|
||||
}
|
||||
|
||||
func first() error {
|
||||
fmt.Println("first")
|
||||
return nil
|
||||
}
|
||||
|
||||
func second() error {
|
||||
fmt.Println("second")
|
||||
return fmt.Errorf("the second error")
|
||||
}
|
||||
|
||||
func third() error {
|
||||
fmt.Println("third")
|
||||
return nil
|
||||
}
|
||||
|
||||
func fourth() error {
|
||||
fmt.Println("fourth")
|
||||
return fmt.Errorf("the fourth error")
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"common/cache"
|
||||
"common/connection"
|
||||
"goutil/logUtilPlus"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// 用户缓存对象
|
||||
var userMap = make(map[int64]*User)
|
||||
var rwmu sync.RWMutex
|
||||
|
||||
// GetUserByID 根据用户id获取用户信息
|
||||
func GetUserByID(UserID int64) (*User, error) {
|
||||
|
||||
//判断缓存是否存在
|
||||
var user *User
|
||||
|
||||
func() *User {
|
||||
rwmu.RLock()
|
||||
defer rwmu.RUnlock()
|
||||
ok := true
|
||||
if user, ok = userMap[UserID]; ok {
|
||||
return user
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
|
||||
if user != nil {
|
||||
return user, nil
|
||||
}
|
||||
|
||||
result := connection.GetUserDB().First(&user, UserID)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
|
||||
//添加缓存
|
||||
func() {
|
||||
rwmu.Lock()
|
||||
defer rwmu.Unlock()
|
||||
user.Cache = cache.NewCache()
|
||||
userMap[user.ID] = user
|
||||
}()
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
// AddUserCache 添加用户缓存
|
||||
func AddUserCache(user *User) {
|
||||
rwmu.Lock()
|
||||
defer rwmu.Unlock()
|
||||
user.Cache = cache.NewCache()
|
||||
userMap[user.ID] = user
|
||||
}
|
||||
|
||||
// AddUser 添加用户
|
||||
// AddUser 添加新的用户到数据库中。
|
||||
// 参数 User: 包含用户信息的对象。
|
||||
// 返回值: 插入操作影响的行数和可能发生的错误。
|
||||
func AddUser(User *User) (int64, error) {
|
||||
|
||||
//处理一些验证
|
||||
|
||||
//写入缓存
|
||||
AddUserCache(User)
|
||||
|
||||
// 写入到数据库
|
||||
result := connection.GetUserDB().Create(&User) // 通过数据的指针来创建
|
||||
|
||||
if result.Error != nil {
|
||||
logUtilPlus.ErrorLog("添加用户失败 错误信息:", result.Error.Error())
|
||||
}
|
||||
return User.ID, nil
|
||||
}
|
||||
|
||||
// Login 用户登录
|
||||
func Login(account string, password string) (*User, error) {
|
||||
|
||||
//这里优先验证缓存数据
|
||||
|
||||
var User User
|
||||
result := connection.GetUserDB().Where("account = ? AND password = ?", account, password).First(&User)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
return &User, nil
|
||||
}
|
||||
Reference in New Issue
Block a user