Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// 批量消费消息请求对象
|
||||
type BatchReceiveMessageRequest struct {
|
||||
// 公共请求参数
|
||||
common *CommonRequest
|
||||
|
||||
// 本次消费的消息数量。取值范围 1-16。(必须)
|
||||
numOfMsg int
|
||||
|
||||
// 本次请求的长轮询等待时间(非必须)
|
||||
pollingWaitSeconds int
|
||||
}
|
||||
|
||||
// 获取请求方法名
|
||||
func (this *BatchReceiveMessageRequest) GetActionName() string {
|
||||
return "BatchReceiveMessage"
|
||||
}
|
||||
|
||||
// SetCommonRequest 设置公共请求对象
|
||||
func (this *BatchReceiveMessageRequest) SetCommonRequest(commonRequest *CommonRequest) {
|
||||
this.common = commonRequest
|
||||
}
|
||||
|
||||
// AssembleParamMap 组装参数字典
|
||||
// 返回值
|
||||
// map[string]string:请求参数字典
|
||||
func (this *BatchReceiveMessageRequest) AssembleParamMap() map[string]string {
|
||||
paramMap := this.common.AssembleParamMap()
|
||||
paramMap["numOfMsg"] = fmt.Sprintf("%d", this.numOfMsg)
|
||||
paramMap["pollingWaitSeconds"] = fmt.Sprintf("%d", this.pollingWaitSeconds)
|
||||
|
||||
return paramMap
|
||||
}
|
||||
|
||||
func NewBatchReceiveMessageRequest(numOfMsg, pollingWaitSeconds int) *BatchReceiveMessageRequest {
|
||||
return &BatchReceiveMessageRequest{
|
||||
numOfMsg: numOfMsg,
|
||||
pollingWaitSeconds: pollingWaitSeconds,
|
||||
}
|
||||
}
|
||||
|
||||
// 批量消费消息请求返回结果对象
|
||||
type BatchReceiveMessageResponse struct {
|
||||
*CommonResponse
|
||||
|
||||
// message信息列表
|
||||
MsgInfoList []*MessageInfo `json:"msgInfoList"`
|
||||
}
|
||||
|
||||
func NewBatchReceiveMessageResponse() *BatchReceiveMessageResponse {
|
||||
return &BatchReceiveMessageResponse{}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package configUtil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
config_Array []map[string]interface{}
|
||||
err_Array error
|
||||
)
|
||||
|
||||
func TestReadJsonConfig_Array(t *testing.T) {
|
||||
config_Array, err_Array = ReadJsonConfig_Array("testdata/jsonConfigArray.ini")
|
||||
if err_Array != nil {
|
||||
t.Errorf("读取JSON配置失败,错误信息为:%s", err_Array)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadIntJsonValue_Array(t *testing.T) {
|
||||
actualValue, err_Array := ReadIntJsonValue_Array(config_Array, "ServerGroupId")
|
||||
if err_Array != nil {
|
||||
t.Errorf("读取JSON配置失败,错误信息为:%s", err_Array)
|
||||
}
|
||||
|
||||
expectedValue := 1
|
||||
if actualValue != expectedValue {
|
||||
t.Errorf("期望的值为%d,实际的值为%d", expectedValue, actualValue)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadStringJsonValue_Array(t *testing.T) {
|
||||
actualValue, err_Array := ReadStringJsonValue_Array(config_Array, "ChatDBConnection")
|
||||
if err_Array != nil {
|
||||
t.Errorf("读取JSON配置失败,错误信息为:%s", err_Array)
|
||||
}
|
||||
|
||||
expectedValue := "root:moqikaka@tcp(192.168.1.226:3306)/chatserver?charset=utf8&parseTime=true&loc=Local&timeout=30s"
|
||||
if actualValue != expectedValue {
|
||||
t.Errorf("期望的值为%s,实际的值为%s", expectedValue, actualValue)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadBoolJsonValue_Array(t *testing.T) {
|
||||
actualValue, err_Array := ReadBoolJsonValue_Array(config_Array, "IfRecordMessage")
|
||||
if err_Array != nil {
|
||||
t.Errorf("读取JSON配置失败,错误信息为:%s", err_Array)
|
||||
}
|
||||
|
||||
expectedValue := true
|
||||
if actualValue != expectedValue {
|
||||
t.Errorf("期望的值为%v,实际的值为%v", expectedValue, actualValue)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package routineCtrlUtil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRoutineCtrl(t *testing.T) {
|
||||
rtCtrl := New(3)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
// 闭包函数避坑注意!!!
|
||||
// 本段代码有坑,请特别注意!!!
|
||||
// *** 待执行函数引用外变变量i,程序可能会出现不符合逻辑的结果(外部变量变化时,闭包函数获取到的是变化后的变量值) ***
|
||||
//rtCtrl.Run(func(arg interface{}) {
|
||||
// fmt.Println(".", i)
|
||||
// time.Sleep(time.Second * 1)
|
||||
// fmt.Println("*", i)
|
||||
// panic("111")
|
||||
//}, nil)
|
||||
|
||||
//-------------------------------------------------
|
||||
// 以下两种方式为正确示例:
|
||||
|
||||
// 避坑方式一:将闭包内使用的外部变量作为参数传入
|
||||
// 将待执行函数内使用的外部变量,用参数传入,可避免不符合逻辑的结果
|
||||
//rtCtrl.Run(func(arg interface{}) {
|
||||
// ii, _ := arg.(int)
|
||||
// fmt.Println(".", ii)
|
||||
// time.Sleep(time.Second * 1)
|
||||
// fmt.Println("*", ii)
|
||||
// panic("111")
|
||||
//}, i)
|
||||
|
||||
// 避坑方式二:将闭包内使用的外部变量固定下来,不让其再被修改
|
||||
temp := i // 这种方式将产生一个局变变量temp,并且temp不会被修改
|
||||
rtCtrl.Run(func(arg interface{}) {
|
||||
fmt.Println(".", temp)
|
||||
time.Sleep(time.Second * 1)
|
||||
fmt.Println("*", temp)
|
||||
panic("111")
|
||||
}, nil)
|
||||
}
|
||||
|
||||
rtCtrl.Wait()
|
||||
fmt.Println("\n==============")
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package gameServerMgr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
. "Framework/managecenterModel"
|
||||
"goutil/logUtil"
|
||||
"goutil/webUtil"
|
||||
)
|
||||
|
||||
//修改区服注册人数
|
||||
func UpdateRegisterCount(serverGroupId, registerCount int32) (err error, success bool) {
|
||||
success = false
|
||||
|
||||
//定义参数
|
||||
requestParamMap := make(map[string]string, 0)
|
||||
requestParamMap["ServerGroupId"] = strconv.Itoa(int(serverGroupId))
|
||||
requestParamMap["Registrations"] = strconv.Itoa(int(registerCount))
|
||||
|
||||
//构造请求url
|
||||
url := fmt.Sprintf("%s/%s", mManageCenterServerAPIUrl, "/API/RegistrationUpdate.ashx")
|
||||
|
||||
//请求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 {
|
||||
return
|
||||
}
|
||||
if statusCode != 200 {
|
||||
err = fmt.Errorf("StatusCode:%d", statusCode)
|
||||
return
|
||||
}
|
||||
|
||||
// 解析返回值
|
||||
returnObj := new(ReturnObject)
|
||||
if err = json.Unmarshal(returnBytes, &returnObj); err != nil {
|
||||
logUtil.ErrorLog(fmt.Sprintf("更新区服注册人数出错,反序列化返回值出错,错误信息为:%s, str:%s", err, string(returnBytes)))
|
||||
return
|
||||
}
|
||||
|
||||
// 判断返回状态是否为成功
|
||||
if returnObj.Code != 0 {
|
||||
err = fmt.Errorf("更新区服注册人数出错,返回状态:%d,信息为:%s", returnObj.Code, returnObj.Message)
|
||||
logUtil.ErrorLog(fmt.Sprintf("更新区服注册人数出错,返回状态:%d,信息为:%s", returnObj.Code, returnObj.Message))
|
||||
return
|
||||
}
|
||||
|
||||
success = true
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user