Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,225 @@
|
||||
package connection
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"framework/sqlAsyncMgr"
|
||||
goredis "github.com/go-redis/redis/v8"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"goutil/logUtilPlus"
|
||||
"time"
|
||||
|
||||
// _ "github.com/go-sql-driver/mysql"
|
||||
config "common/configsYaml"
|
||||
"goutil/mysqlUtil"
|
||||
"goutil/redisUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
adminDB *gorm.DB //管理员数据库对象
|
||||
userDB *gorm.DB //用户数据库对象
|
||||
gameModelDB *gorm.DB // 游戏模型数据库对象
|
||||
gameDB *gorm.DB // 游戏数据库
|
||||
gamePlayerDB *gorm.DB // 玩家库
|
||||
redisDB *goredis.Client // 游戏redis连接客户端
|
||||
syncMgr *sqlAsyncMgr.SqlAsyncUtil // 同步管理对象
|
||||
syncFileSize = 1024 * 1024 // 同步文件大小
|
||||
fileMaxSaveTime = 24 * 7 // 保留7天的sql文件
|
||||
)
|
||||
|
||||
var excuteSqlFunc func(*gorm.DB, ITable, string) error
|
||||
var loghandle func(s string, is ...interface{})
|
||||
var defaultType = SyncSql
|
||||
|
||||
type ITable interface {
|
||||
TableName() string
|
||||
}
|
||||
|
||||
type SqlExecuteType int32
|
||||
|
||||
const (
|
||||
SyncSql SqlExecuteType = iota
|
||||
ASyncSql
|
||||
Name = "BaseDal"
|
||||
)
|
||||
|
||||
// init
|
||||
// @description: init
|
||||
// parameter:
|
||||
// return:
|
||||
func init() {
|
||||
|
||||
//管理中心数据库配置
|
||||
adminDB = initMysql(config.GetDbConfig().GetAdminConfig())
|
||||
userDB = initMysql(config.GetDbConfig().GetUserConfig())
|
||||
|
||||
// 初始化游戏模型数据库
|
||||
gameModelDBConfig := config.GetDbConfig().GetGameModelConfig()
|
||||
gameModelDB = initMysql(gameModelDBConfig)
|
||||
|
||||
// 初始化crossSever 游戏数据库
|
||||
gameDBConfig := config.GetDbConfig().GetGameConfig()
|
||||
gameDB = initMysql(gameDBConfig)
|
||||
gamePlayerDB = initMysql(config.GetDbConfig().GetPlayerConfig())
|
||||
|
||||
// 初始化redis-client
|
||||
excuteSqlFunc = func(gdb *gorm.DB, table ITable, sql string) error {
|
||||
db := gdb.Exec(sql)
|
||||
if db.Error != nil {
|
||||
loghandle("sql执行错误:%s;错误信息:%v", sql, db.Error.Error())
|
||||
return db.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
redisDB = initRedis(config.GetDbConfig().GetRedisConfig())
|
||||
}
|
||||
|
||||
// 初始化Mysql
|
||||
// initMysql
|
||||
// @description: 初始化Mysql
|
||||
// parameter:
|
||||
// @dbConfig: dbConfig
|
||||
// return:
|
||||
// @*gorm.DB: DB
|
||||
func initMysql(dbConfig *mysqlUtil.DBConfig) *gorm.DB {
|
||||
|
||||
//不存在配置
|
||||
if dbConfig == nil || dbConfig.ConnectionString == "" {
|
||||
return nil
|
||||
}
|
||||
logUtilPlus.WarnLog("开始连接mysql:%s", dbConfig.ConnectionString)
|
||||
dbObj, err := gorm.Open(mysql.Open(dbConfig.ConnectionString), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("初始化数据库:%s失败,错误信息为:%s", dbConfig.ConnectionString, err))
|
||||
}
|
||||
logUtilPlus.WarnLog("连接mysql:%s成功", dbConfig.ConnectionString)
|
||||
|
||||
return dbObj
|
||||
}
|
||||
|
||||
// initRedis
|
||||
// @description: 初始化redis客户端
|
||||
// parameter:
|
||||
// @redisConfig: redisConfig
|
||||
// return:
|
||||
// @*goredis.Client: Client
|
||||
func initRedis(redisConfig *redisUtil.RedisConfig) *goredis.Client {
|
||||
|
||||
client := goredis.NewClient(&goredis.Options{
|
||||
Addr: redisConfig.ConnectionString,
|
||||
Password: redisConfig.Password,
|
||||
DB: redisConfig.Database,
|
||||
IdleTimeout: redisConfig.IdleTimeout,
|
||||
DialTimeout: redisConfig.DialConnectTimeout,
|
||||
})
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
ping, err := client.Ping(ctx).Result()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("ping->redis:%s失败,DB:%s,错误信息为:%s", redisConfig.ConnectionString, redisConfig.Database, err))
|
||||
}
|
||||
|
||||
logUtilPlus.WarnLog("ping->redis:%s成功,信息为:%s", redisConfig.ConnectionString, ping)
|
||||
return client
|
||||
}
|
||||
|
||||
// GetAdminDB
|
||||
// @description: 获取admin库db实例
|
||||
// parameter:
|
||||
// return:
|
||||
// @*gorm.DB:admin库db实例
|
||||
func GetAdminDB() *gorm.DB {
|
||||
return adminDB
|
||||
}
|
||||
|
||||
// GetUserDB
|
||||
// @description: 获取user库db实例
|
||||
// parameter:
|
||||
// return:
|
||||
// @*gorm.DB:user库db实例
|
||||
func GetUserDB() *gorm.DB {
|
||||
return userDB
|
||||
}
|
||||
|
||||
// GetGameDB
|
||||
// @description: 获取game库db实例
|
||||
// parameter:
|
||||
// return:
|
||||
// @*gorm.DB:game库db实例
|
||||
func GetGameDB() *gorm.DB {
|
||||
return gameDB
|
||||
}
|
||||
|
||||
// GetPlayerDB
|
||||
// @description: 获取玩家库db实例
|
||||
// parameter:
|
||||
// return:
|
||||
// @*gorm.DB:玩家库db实例
|
||||
func GetPlayerDB() *gorm.DB {
|
||||
return gamePlayerDB
|
||||
}
|
||||
|
||||
// GetGameModelDB
|
||||
// @description: 获取model库db实例
|
||||
// parameter:
|
||||
// return:
|
||||
// @*gorm.DB:model库db实例
|
||||
func GetGameModelDB() *gorm.DB {
|
||||
return gameModelDB
|
||||
}
|
||||
|
||||
// GetRedisClient
|
||||
// @description: 获取redisdb实例
|
||||
// parameter:
|
||||
// return:
|
||||
// @*goredis.Client:redisdb实例
|
||||
func GetRedisClient() *goredis.Client {
|
||||
return redisDB
|
||||
}
|
||||
|
||||
// GetAll
|
||||
// @description: 获取model数据
|
||||
// parameter:
|
||||
// @dataList:数据列表
|
||||
// return:
|
||||
// @error:错误信息
|
||||
func GetAll(dataList interface{}) error {
|
||||
mysqlObj := GetGameModelDB()
|
||||
if mysqlObj = mysqlObj.Find(dataList); mysqlObj.Error != nil {
|
||||
WriteLog("dal.GetAll", mysqlObj.Error)
|
||||
return mysqlObj.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetGameModelData
|
||||
// @description: 获取GameModel数据
|
||||
// parameter:
|
||||
// @moduleName:模块名称
|
||||
// @dataList:数据列表
|
||||
// return:
|
||||
// @error:错误信息
|
||||
func GetGameModelData(moduleName string, dataList interface{}) error {
|
||||
if result := gameModelDB.Find(dataList); result.Error != nil {
|
||||
WriteLog(moduleName+"GetGameModelData", result.Error)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteLog
|
||||
// @description: 记录错误日志
|
||||
// parameter:
|
||||
// @command:命令
|
||||
// @err:错误信息
|
||||
// return:
|
||||
func WriteLog(command string, err error) {
|
||||
logUtilPlus.ErrorLog(fmt.Sprintf("Scan失败,错误信息:%s,command:%s", err, command))
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package model
|
||||
|
||||
// 消费消息请求对象
|
||||
type GetQueueAttributesRequest struct {
|
||||
// 公共请求参数
|
||||
common *CommonRequest
|
||||
}
|
||||
|
||||
// 获取请求方法名
|
||||
func (this *GetQueueAttributesRequest) GetActionName() string {
|
||||
return "GetQueueAttributes"
|
||||
}
|
||||
|
||||
// SetCommonRequestObject 设置公共请求对象
|
||||
func (this *GetQueueAttributesRequest) SetCommonRequest(commonRequest *CommonRequest) {
|
||||
this.common = commonRequest
|
||||
}
|
||||
|
||||
// AssembleParamMap 组装参数字典
|
||||
// 返回值
|
||||
// map[string]string:请求参数字典
|
||||
func (this *GetQueueAttributesRequest) AssembleParamMap() map[string]string {
|
||||
paramMap := this.common.AssembleParamMap()
|
||||
|
||||
return paramMap
|
||||
}
|
||||
|
||||
func NewGetQueueAttributesRequest() *GetQueueAttributesRequest {
|
||||
return &GetQueueAttributesRequest{}
|
||||
}
|
||||
|
||||
// 消费消息请求返回结果对象
|
||||
type GetQueueAttributesResponse struct {
|
||||
*CommonResponse
|
||||
|
||||
MaxMsgHeapNum int `json:"maxMsgHeapNum"` // 最大堆积消息数。取值范围在公测期间为 1,000,000 - 10,000,000,正式上线后范围可达到 1000,000-1000,000,000。默认取值在公测期间为 10,000,000,正式上线后为 100,000,000。
|
||||
PollingWaitSeconds int `json:"pollingWaitSeconds"` // 消息接收长轮询等待时间。取值范围0 - 30秒,默认值0。
|
||||
VisibilityTimeout int `json:"visibilityTimeout"` // 消息可见性超时。取值范围1 - 43200秒(即12小时内),默认值30。
|
||||
MaxMsgSize int `json:"maxMsgSize"` // 消息最大长度。取值范围1024 - 1048576 Byte(即1K - 1024K),默认值65536。
|
||||
MsgRetentionSeconds int `json:"msgRetentionSeconds"` // 消息保留周期。取值范围60-1296000秒(1min-15天),默认值345600秒(4 天)。
|
||||
CreateTime int `json:"createTime"` // 队列的创建时间。返回 Unix 时间戳,精确到秒。
|
||||
LastModifyTime int `json:"lastModifyTime"` // 最后一次修改队列属性的时间。返回 Unix 时间戳,精确到秒。
|
||||
ActiveMsgNum int `json:"activeMsgNum"` // 在队列中处于 Active 状态(不处于被消费状态)的消息总数,为近似值。
|
||||
InactiveMsgNum int `json:"inactiveMsgNum"` // 在队列中处于 Inactive 状态(正处于被消费状态)的消息总数,为近似值。
|
||||
RewindSeconds int `json:"rewindSeconds"` // 回溯队列的消息回溯时间最大值,取值范围0 - 43200秒,0表示不开启消息回溯。
|
||||
RewindmsgNum int `json:"rewindmsgNum"` // 已调用 DelMsg 接口删除,但还在回溯保留时间内的消息数量。
|
||||
MinMsgTime int `json:"minMsgTime"` // 消息最小未消费时间,单位为秒。
|
||||
QueueName string `json:"queueName"` // 消息队列名字。
|
||||
QueueId string `json:"queueId"` // 消息队列ID。
|
||||
CreateUin int64 `json:"createUin"` // 创建者Uin。
|
||||
Bps int `json:"Bps"` // 带宽限制。
|
||||
Qps int `json:"qps"` // 每秒钟生产消息条数的限制,消费消息的大小是该值的1.1倍。
|
||||
Tags []string `json:"tags"` // 关联的标签。
|
||||
}
|
||||
|
||||
func NewGetQueueAttributesResponse() *GetQueueAttributesResponse {
|
||||
return &GetQueueAttributesResponse{}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package httpSender
|
||||
|
||||
// 发送器
|
||||
// 用于发送Requester
|
||||
type Sender interface {
|
||||
Send(req Requester) ([]byte, error)
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package contextcheckMgr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"goutil/logUtil"
|
||||
"goutil/securityUtil"
|
||||
"goutil/webUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
//接口密钥Id
|
||||
msecretId string = "c98276c73c122eaa65163fe431cbf7d4"
|
||||
//接口密钥key
|
||||
msecretKey string = "3d2b39f824fa2f992494e17be500e303"
|
||||
//业务ID
|
||||
mbusinessId string = "9559ce74b5c5d24f6b124799a53c7431"
|
||||
//接口请求地址
|
||||
mapiurl string = "http://as.dun.163.com/v3/text/check"
|
||||
//版本号
|
||||
mversion string = "v3.1"
|
||||
)
|
||||
|
||||
//参数设置
|
||||
func SetPara(secretId, secretKey, businessId, apiurl, version string) {
|
||||
msecretId = secretId
|
||||
msecretKey = secretKey
|
||||
mbusinessId = businessId
|
||||
mapiurl = apiurl
|
||||
mversion = version
|
||||
}
|
||||
|
||||
//content:用户发表内容
|
||||
//account:玩家账号(用户唯一标识)
|
||||
//nickname:角色名称
|
||||
//extStr1:角色区服名称
|
||||
//extStr2:UserId
|
||||
//ip:用户IP地址,建议抄送,辅助机审策略精准调优
|
||||
//extLon1:区服ID
|
||||
//返回值 code: 0:通过, 1:嫌疑,2:不通过
|
||||
//文本内容检测
|
||||
func TextCheck(content, account, nickname, extStr1, extStr2, ip string, extLon1 int64) (code int, err error) {
|
||||
//构造请求参数
|
||||
postDataDict := make(map[string]string)
|
||||
postDataDict["secretId"] = msecretId
|
||||
postDataDict["businessId"] = mbusinessId
|
||||
postDataDict["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
|
||||
postDataDict["nonce"] = strconv.FormatInt(rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(10000000000), 10)
|
||||
rawString := fmt.Sprintf("%v%v%v", account, postDataDict["timestamp"], content)
|
||||
postDataDict["dataId"] = securityUtil.Md5String(rawString, false)
|
||||
postDataDict["content"] = content
|
||||
postDataDict["version"] = mversion
|
||||
postDataDict["account"] = account
|
||||
postDataDict["nickname"] = nickname
|
||||
postDataDict["extLon1"] = strconv.FormatInt(extLon1, 10)
|
||||
// postDataDict["extLon2"] = extLon2
|
||||
postDataDict["extStr1"] = extStr1
|
||||
postDataDict["extStr2"] = extStr2
|
||||
postDataDict["ip"] = ip
|
||||
postDataDict["signature"] = getSignature(postDataDict)
|
||||
|
||||
//请求url,请求头
|
||||
header := webUtil.GetFormHeader()
|
||||
transport := webUtil.NewTransport()
|
||||
transport.DisableKeepAlives = true
|
||||
transport = webUtil.GetTimeoutTransport(transport, 30)
|
||||
|
||||
//请求接口
|
||||
statusCode, result, err := webUtil.PostMapData(mapiurl, postDataDict, header, transport)
|
||||
//定义错误信息
|
||||
var logMessage string
|
||||
|
||||
//post请求错误
|
||||
if err != nil {
|
||||
logMessage = fmt.Sprintf("TextCheck:,错误信息为:%s", err.Error())
|
||||
logUtil.ErrorLog(logMessage)
|
||||
return
|
||||
}
|
||||
if statusCode != 200 {
|
||||
logMessage = fmt.Sprintf("TextCheck:%d is wrong", statusCode)
|
||||
logUtil.ErrorLog(logMessage)
|
||||
err = fmt.Errorf("TextCheck:%d is wrong", statusCode)
|
||||
return
|
||||
}
|
||||
|
||||
//反序列化结果
|
||||
var checkResponseObj *ResultModel
|
||||
err = json.Unmarshal(result, &checkResponseObj)
|
||||
if err != nil {
|
||||
logMessage = fmt.Sprintf("json.Unmarshal(checkResponseObj),err:%s", err.Error())
|
||||
logUtil.ErrorLog(logMessage)
|
||||
return
|
||||
}
|
||||
|
||||
//判断接口是否调用成功
|
||||
if checkResponseObj.Code != 200 {
|
||||
logMessage = fmt.Sprintf("TextCheck接口调用失败,ResultStatus %d", checkResponseObj.Code)
|
||||
err = fmt.Errorf("TextCheck接口调用失败,code:%d", checkResponseObj.Code)
|
||||
return
|
||||
}
|
||||
|
||||
//返回检测结果
|
||||
code = checkResponseObj.Result.Action
|
||||
return
|
||||
}
|
||||
|
||||
//生成签名字符串
|
||||
func getSignature(postDataDict map[string]string) string {
|
||||
var paramStr string
|
||||
keys := make([]string, 0, len(postDataDict))
|
||||
for k := range postDataDict {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
paramStr += key + postDataDict[key]
|
||||
}
|
||||
paramStr += msecretKey
|
||||
|
||||
return securityUtil.Md5String(paramStr, false)
|
||||
}
|
||||
Reference in New Issue
Block a user