Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package monitorNewMgr
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"goutil/stringUtil"
|
||||
)
|
||||
|
||||
const (
|
||||
// CON_MONITOR_HISTORY_SIZE 历史监控信息保存数量
|
||||
CON_MONITOR_HISTORY_SIZE = 3
|
||||
|
||||
// CON_MONITOR_HISTORY_VALID_SECONDS 历史监控信息有效的秒数
|
||||
CON_MONITOR_HISTORY_VALID_SECONDS = 30
|
||||
|
||||
// CON_MONITOR_HISTORY_SIMILARITY_THERSHOLD 历史监控信息相似度的阈值
|
||||
CON_MONITOR_HISTORY_SIMILARITY_THERSHOLD = 0.9
|
||||
)
|
||||
|
||||
var (
|
||||
monitorHistoryList = make([]*MonitorHistory, 0, CON_MONITOR_HISTORY_SIZE)
|
||||
monitorHistoryMutex sync.Mutex
|
||||
)
|
||||
|
||||
func checkSimilarity(monitorMessage string, timestamp int64) (valid bool) {
|
||||
//默认监控信息有效
|
||||
valid = true
|
||||
|
||||
monitorHistoryMutex.Lock()
|
||||
defer monitorHistoryMutex.Unlock()
|
||||
|
||||
// 从后往前(按时间从后往前)遍历,以便于可以及时退出
|
||||
for i := len(monitorHistoryList) - 1; i >= 0; i-- {
|
||||
item := monitorHistoryList[i]
|
||||
|
||||
// 如果已经过期,则不用处理; 返回之前的状态即可(当前的已经过期,则之前的也一定已经过期)
|
||||
if time.Now().Unix()-item.Timestamp > CON_MONITOR_HISTORY_VALID_SECONDS {
|
||||
break
|
||||
}
|
||||
|
||||
// 如果两个字符串的长度相差2倍,则无须继续判断,继续与下一条数据进行比较
|
||||
lenA, lenB := len(monitorMessage), len(item.MonitorMessage)
|
||||
if lenA > 2*lenB || lenB > 2*lenA {
|
||||
continue
|
||||
}
|
||||
|
||||
// 判断两个字符串的相似度(如果相似度超过阈值,则此日志无效)
|
||||
_, similarity := stringUtil.Similarity(monitorMessage, item.MonitorMessage)
|
||||
if similarity >= CON_MONITOR_HISTORY_SIMILARITY_THERSHOLD {
|
||||
valid = false
|
||||
return // 直接返回,无需将当前日志添加到历史列表中,以提高性能
|
||||
}
|
||||
}
|
||||
|
||||
// 将消息添加到历史消息列表中
|
||||
monitorHistoryList = append(monitorHistoryList, newMonitorHistory(monitorMessage, timestamp))
|
||||
if len(monitorHistoryList) > CON_MONITOR_HISTORY_SIZE {
|
||||
monitorHistoryList = monitorHistoryList[len(monitorHistoryList)-CON_MONITOR_HISTORY_SIZE:]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"common/cache"
|
||||
"common/connection"
|
||||
)
|
||||
|
||||
func init() {
|
||||
//注册数据库
|
||||
connection.RegisterDBModel(&User{})
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int64 `gorm:"column:id;primary_key;comment:用户id;autoIncrementIncrement" json:"id"`
|
||||
//账号
|
||||
Account string `gorm:"column:account;comment:账号" json:"account"`
|
||||
Name string `gorm:"column:name;comment:用户名称" json:"name"`
|
||||
Password string `gorm:"column:password;comment:用户密码" json:"password"`
|
||||
//性别
|
||||
Sex int32 `gorm:"column:sex;comment:性别" json:"sex"`
|
||||
//生日
|
||||
Birthday string `gorm:"column:birthday;comment:生日" json:"birthday"`
|
||||
//手机
|
||||
Phone int64 `gorm:"column:phone;comment:手机" json:"phone"`
|
||||
//邮箱
|
||||
Email string `gorm:"column:email;comment:邮箱" json:"email"`
|
||||
//备注
|
||||
Describe string `gorm:"column:describe;comment:备注" json:"describe"`
|
||||
|
||||
//玩家的缓存对象
|
||||
Cache *cache.Cache
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
return "user"
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package webServer
|
||||
|
||||
import (
|
||||
"common/resultStatus"
|
||||
)
|
||||
|
||||
// ResponseObject
|
||||
// @description: 响应对象
|
||||
type ResponseObject struct {
|
||||
// 响应结果的状态值
|
||||
Code resultStatus.StatusCode
|
||||
|
||||
// Status 状态
|
||||
Status int32
|
||||
|
||||
// 响应结果的状态值所对应的描述信息
|
||||
Message string
|
||||
|
||||
// 响应结果的数据
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
// SetResultStatus
|
||||
// @description: 设置响应结果的状态值
|
||||
// parameter:
|
||||
// @receiver this: this
|
||||
// @rs: 响应结果的状态值
|
||||
// return:
|
||||
// @*ResponseObject: 响应结果对象
|
||||
func (this *ResponseObject) SetResultStatus(rs resultStatus.ResultStatus) *ResponseObject {
|
||||
this.Code = rs.Code()
|
||||
this.Message = rs.Message()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
// SetData
|
||||
// @description: 设置响应对象数据
|
||||
// parameter:
|
||||
// @receiver this: this
|
||||
// @data: 响应结果的数据
|
||||
// return:
|
||||
// @*ResponseObject: 响应结果对象
|
||||
func (this *ResponseObject) SetData(data interface{}) *ResponseObject {
|
||||
this.Value = data
|
||||
return this
|
||||
}
|
||||
|
||||
// IsSuccess
|
||||
// @description: 是否是请求成功
|
||||
// parameter:
|
||||
// @receiver this:this
|
||||
// return:
|
||||
// @bool:是请求成功
|
||||
func (this *ResponseObject) IsSuccess() bool {
|
||||
return this.Code == resultStatus.Success.Code()
|
||||
}
|
||||
|
||||
// SetCodeStatus
|
||||
// @description: 同步code和status状态
|
||||
// parameter:
|
||||
// @receiver this:this
|
||||
// return:
|
||||
func (this *ResponseObject) SetCodeStatus() {
|
||||
if this.Code == resultStatus.Success.Code() && resultStatus.StatusCode(this.Status) != resultStatus.Success.Code() {
|
||||
this.Code = resultStatus.StatusCode(this.Status)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetInitResponseObj
|
||||
// @description: 获取初始的响应对象
|
||||
// parameter:
|
||||
// return:
|
||||
// @*ResponseObject: 响应对象
|
||||
func GetInitResponseObj() *ResponseObject {
|
||||
return &ResponseObject{
|
||||
Code: resultStatus.Success.Code(),
|
||||
Message: "",
|
||||
Value: nil,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package managecenterModel
|
||||
|
||||
import (
|
||||
. "goutil/mysqlUtil"
|
||||
. "goutil/redisUtil"
|
||||
)
|
||||
|
||||
// 数据库连接字符串配置
|
||||
type DBConnectionConfig struct {
|
||||
// 模型数据库内网连接字符串
|
||||
GameModelDB string
|
||||
|
||||
// 游戏数据库内网连接字符串
|
||||
GameDB string
|
||||
|
||||
// 日志数据库内网连接字符串
|
||||
LogDB string
|
||||
|
||||
// Redis连接字符串
|
||||
RedisConfig string
|
||||
}
|
||||
|
||||
// 获取游戏模型数据库连接
|
||||
// 返回值:
|
||||
// 数据库连接配置对象
|
||||
// 错误对象
|
||||
func (this *DBConnectionConfig) GetGameModelDBConn() (dbConfig *DBConfig, err error) {
|
||||
dbConfig, err = NewDBConfig2(this.GameModelDB)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取游戏数据库连接
|
||||
// 返回值:
|
||||
// 数据库连接配置对象
|
||||
// 错误对象
|
||||
func (this *DBConnectionConfig) GetGameDBConn() (dbConfig *DBConfig, err error) {
|
||||
dbConfig, err = NewDBConfig2(this.GameDB)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取游戏日志数据库连接
|
||||
// 返回值:
|
||||
// 数据库连接配置对象
|
||||
// 错误对象
|
||||
func (this *DBConnectionConfig) GetLogDBConn() (dbConfig *DBConfig, err error) {
|
||||
dbConfig, err = NewDBConfig2(this.LogDB)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取Redis配置
|
||||
// 返回值:
|
||||
// redis配置对象
|
||||
// 错误对象
|
||||
func (this *DBConnectionConfig) GetRedisConfig() (redisConfig *RedisConfig, err error) {
|
||||
redisConfig, err = NewRedisConfig(this.RedisConfig)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user