Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package httpServer
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// methodAndInOutTypes
|
||||
// @description: 反射的方法和输入、输出参数类型组合类型
|
||||
type methodAndInOutTypes struct {
|
||||
// 反射出来的对应方法对象
|
||||
Method reflect.Value
|
||||
|
||||
// 反射出来的方法的输入参数的类型集合
|
||||
InTypes []reflect.Type
|
||||
|
||||
// 反射出来的方法的输出参数的类型集合
|
||||
OutTypes []reflect.Type
|
||||
}
|
||||
|
||||
// newmethodAndInOutTypes
|
||||
// @description: newmethodAndInOutTypes
|
||||
// parameter:
|
||||
// @_method: _method
|
||||
// @_inTypes: _inTypes
|
||||
// @_outTypes: _outTypes
|
||||
// return:
|
||||
// @*methodAndInOutTypes: methodAndInOutTypes
|
||||
func newmethodAndInOutTypes(_method reflect.Value, _inTypes []reflect.Type, _outTypes []reflect.Type) *methodAndInOutTypes {
|
||||
return &methodAndInOutTypes{
|
||||
Method: _method,
|
||||
InTypes: _inTypes,
|
||||
OutTypes: _outTypes,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package logUtilPlus
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"goutil/debugUtil"
|
||||
"goutil/esLogUtil"
|
||||
"goutil/logUtil"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
enableDebugLog = true
|
||||
enableInfoLog = true
|
||||
enableWarnLog = true
|
||||
)
|
||||
|
||||
// 设置日志级别
|
||||
// debug / all 时全部开启
|
||||
// info 记录 info/warn/error/fatal
|
||||
// warn 记录 warn/error/fatal
|
||||
// error 记录 error/fatal
|
||||
func SetLevel(level string) {
|
||||
// 大写不敏感
|
||||
level = strings.ToLower(level)
|
||||
|
||||
//全部开启
|
||||
if level == "debug" || level == "all" {
|
||||
// debug / all 时全部开启
|
||||
enableInfoLog = true
|
||||
enableDebugLog = true
|
||||
enableWarnLog = true
|
||||
} else if level == "info" {
|
||||
// info 记录 info/warn/error/fatal
|
||||
enableDebugLog = false
|
||||
enableInfoLog = true
|
||||
enableWarnLog = true
|
||||
} else if level == "warn" {
|
||||
// warn 记录 warn/error/fatal
|
||||
enableDebugLog = false
|
||||
enableInfoLog = false
|
||||
enableWarnLog = true
|
||||
} else if level == "error" {
|
||||
// error 记录 error/fatal
|
||||
enableInfoLog = false
|
||||
enableDebugLog = false
|
||||
enableWarnLog = false
|
||||
}
|
||||
}
|
||||
|
||||
// 启动ES日志系统(不调用则不启动ES日志系统,默认记录本地)
|
||||
// 参数:
|
||||
//
|
||||
// esUrls:ES地址(多个地址使用,分割)
|
||||
// name:IndexName
|
||||
// serverGroupId:服务器组Id
|
||||
//
|
||||
// 返回值:
|
||||
//
|
||||
// 结果状态
|
||||
func Start(esUrls string, name string, serverGroupId int32) {
|
||||
esLogUtil.Start(esUrls, name, serverGroupId)
|
||||
}
|
||||
|
||||
// 停止服务
|
||||
func Stop() {
|
||||
esLogUtil.Stop()
|
||||
}
|
||||
|
||||
// 调试日志
|
||||
func InfoLog(format string, args ...interface{}) {
|
||||
if !enableInfoLog {
|
||||
return
|
||||
}
|
||||
PrintAndWriteLog(logUtil.Info, format, args...)
|
||||
}
|
||||
|
||||
// 警告日志
|
||||
func WarnLog(format string, args ...interface{}) {
|
||||
if !enableWarnLog {
|
||||
return
|
||||
}
|
||||
PrintAndWriteLog(logUtil.Warn, format, args...)
|
||||
}
|
||||
|
||||
// 调试日志
|
||||
func DebugLog(format string, args ...interface{}) {
|
||||
if !enableDebugLog {
|
||||
return
|
||||
}
|
||||
PrintAndWriteLog(logUtil.Debug, format, args...)
|
||||
}
|
||||
|
||||
// 错误日志
|
||||
func ErrorLog(format string, args ...interface{}) {
|
||||
PrintAndWriteLog(logUtil.Error, format, args...)
|
||||
}
|
||||
|
||||
// 致命错误日志
|
||||
func FatalLog(format string, args ...interface{}) {
|
||||
PrintAndWriteLog(logUtil.Fatal, format, args...)
|
||||
}
|
||||
|
||||
// 打印到控制台并写日志
|
||||
func PrintAndWriteLog(logType logUtil.LogType, format string, args ...interface{}) {
|
||||
//控制台打印一行
|
||||
PrintLog(format, args...)
|
||||
|
||||
if len(args) <= 0 {
|
||||
logUtil.NormalLog(format, logType)
|
||||
esLogUtil.NormalLog(format, logType)
|
||||
} else {
|
||||
logUtil.NormalLog(fmt.Sprintf(format, args...), logType)
|
||||
esLogUtil.NormalLog(fmt.Sprintf(format, args...), logType)
|
||||
}
|
||||
|
||||
if debugUtil.IsDebug() && (logType == logUtil.Warn || logType == logUtil.Error || logType == logUtil.Fatal) {
|
||||
StdLog(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// 控制台打印
|
||||
func PrintLog(format string, args ...interface{}) {
|
||||
//避免非DEBUG模式下组装字符串,提前判断一次
|
||||
if debugUtil.IsDebug() {
|
||||
debugUtil.Println(fmt.Sprintf(format, args...))
|
||||
}
|
||||
}
|
||||
|
||||
// 标准库控制台输出打印
|
||||
func StdLog(format string, args ...interface{}) {
|
||||
if len(args) <= 0 {
|
||||
log.Print(format)
|
||||
} else {
|
||||
log.Print(fmt.Sprintf(format, args...))
|
||||
}
|
||||
}
|
||||
|
||||
// 记录未知错误日志
|
||||
// 参数:
|
||||
//
|
||||
// err:recover获取到的错误对象
|
||||
// args:附加参数
|
||||
func LogUnknownError(err interface{}, args ...string) {
|
||||
logUtil.LogUnknownError(err, args...)
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package mysqlSync
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"goutil/fileUtil"
|
||||
"goutil/logUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
// 记录错误sql命令的文件名
|
||||
con_Error_FileName = "errorFile.txt"
|
||||
)
|
||||
|
||||
// 定义处理错误命令的文件对象
|
||||
type errorFile struct {
|
||||
// 错误文件
|
||||
file *os.File
|
||||
|
||||
// 文件路径
|
||||
filePath string
|
||||
|
||||
// 同步数据对象的唯一标识,用于进行重复判断
|
||||
identifier string
|
||||
}
|
||||
|
||||
// 保存命令到错误文件
|
||||
// command: sql命令
|
||||
func (this *errorFile) SaveCommand(command string) {
|
||||
this.open()
|
||||
defer this.close()
|
||||
|
||||
// 覆盖写入
|
||||
this.file.Seek(0, 0)
|
||||
|
||||
// 写入命令
|
||||
_, err := this.file.WriteString(command)
|
||||
if err != nil {
|
||||
prefix := fmt.Sprintf("%s-%s", this.identifier, "errorFile.SaveCommand")
|
||||
err = fmt.Errorf("%s-Write %s to file failed:%s", prefix, command, err)
|
||||
logUtil.ErrorLog(err.Error())
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 清理残留数据
|
||||
this.file.Truncate(int64(len(command)))
|
||||
}
|
||||
|
||||
// 读取文件中命令
|
||||
func (this *errorFile) ReadCommand() string {
|
||||
this.open()
|
||||
defer this.close()
|
||||
|
||||
this.file.Seek(0, 0)
|
||||
content, err := ioutil.ReadAll(this.file)
|
||||
if err != nil {
|
||||
prefix := fmt.Sprintf("%s-%s", this.identifier, "errorFile.ReadCommand")
|
||||
err = fmt.Errorf("%s-Read command failed:%s", prefix, err)
|
||||
logUtil.ErrorLog(err.Error())
|
||||
panic(err)
|
||||
}
|
||||
return string(content)
|
||||
}
|
||||
|
||||
// 打开文件
|
||||
func (this *errorFile) open() {
|
||||
// 打开errorFile文件, 如果没有就创建
|
||||
var err error
|
||||
this.file, err = os.OpenFile(this.filePath, os.O_CREATE|os.O_RDWR, os.ModePerm|os.ModeTemporary)
|
||||
if err != nil {
|
||||
prefix := fmt.Sprintf("%s-%s", this.identifier, "errorFile.newErrorFile.os.OpenFile")
|
||||
err = fmt.Errorf("%s-Open File failed:%s", prefix, err)
|
||||
logUtil.ErrorLog(err.Error())
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭文件
|
||||
func (this *errorFile) close() {
|
||||
this.file.Close()
|
||||
}
|
||||
|
||||
// 删除文件
|
||||
func (this *errorFile) Delete() {
|
||||
fileUtil.DeleteFile(this.filePath)
|
||||
}
|
||||
|
||||
// 构造错误文件对象
|
||||
// _dirPath:文件路径
|
||||
// _identifier:唯一标识
|
||||
func newErrorFile(_dirPath string, _identifier string) *errorFile {
|
||||
_filePath := filepath.Join(_dirPath, con_Error_FileName)
|
||||
return &errorFile{
|
||||
filePath: _filePath,
|
||||
identifier: _identifier,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package configMgr
|
||||
|
||||
import (
|
||||
"goutil/configUtil"
|
||||
)
|
||||
|
||||
// 配置管理对象
|
||||
type ConfigManager struct {
|
||||
// 初始化方法列表
|
||||
initFuncList []func(*configUtil.XmlConfig) error
|
||||
}
|
||||
|
||||
// 注册初始化方法
|
||||
func (this *ConfigManager) RegisterInitFunc(initFunc func(*configUtil.XmlConfig) error) {
|
||||
this.initFuncList = append(this.initFuncList, initFunc)
|
||||
}
|
||||
|
||||
// 初始化
|
||||
func (this *ConfigManager) Init(configObj *configUtil.XmlConfig) error {
|
||||
for _, initFunc := range this.initFuncList {
|
||||
if err := initFunc(configObj); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 创建配置管理对象
|
||||
func NewConfigManager() *ConfigManager {
|
||||
return &ConfigManager{
|
||||
initFuncList: make([]func(*configUtil.XmlConfig) error, 0, 8),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package httpServer
|
||||
|
||||
import (
|
||||
"common/webServer"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"goutil/logUtilPlus"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// responseResult
|
||||
// @description: responseResult
|
||||
// parameter:
|
||||
// @w: w
|
||||
// @responseObj: responseObj
|
||||
// return:
|
||||
func responseResult(w http.ResponseWriter, responseObj *webServer.ResponseObject) {
|
||||
b, err := json.Marshal(responseObj)
|
||||
if err != nil {
|
||||
logUtilPlus.ErrorLog(fmt.Sprintf("序列化输出结果%v出错", responseObj))
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Length", strconv.Itoa(len(b)))
|
||||
w.Write(b)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package qcloud
|
||||
|
||||
// 腾讯云平台的响应信息
|
||||
|
||||
// 响应信息
|
||||
type QCloudResponse struct {
|
||||
Result int // 0表示成功(计费依据),非0表示失败
|
||||
Errmsg string // result非0时的具体错误信息
|
||||
Ext string // 用户的session内容,腾讯server回包中会原样返回
|
||||
Sid string // 标识本次发送id,标识一次短信下发记录
|
||||
Fee int // 短信计费的条数
|
||||
Detail []responsDetailItem // 群发短信时才有
|
||||
}
|
||||
|
||||
type responsDetailItem struct {
|
||||
Result int
|
||||
Errmsg string
|
||||
Mobile string
|
||||
Nationcode string
|
||||
Sid string
|
||||
Fee int
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"ServerGroupId": 1,
|
||||
"ChatDBConnection": "root:moqikaka@tcp(192.168.1.226:3306)/chatserver?charset=utf8&parseTime=true&loc=Local&timeout=30s",
|
||||
"ChatDBMaxOpenConns": 10,
|
||||
"ChatDBMaxIdleConns": 5,
|
||||
"ModelDBConnection": "root:moqikaka@tcp(192.168.1.226:3306)/dzz_model_online?charset=utf8&parseTime=true&loc=Local&timeout=30s",
|
||||
"ModelDBMaxOpenConns": 0,
|
||||
"ModelDBMaxIdleConns": 0,
|
||||
"GameDBConnection": "root:moqikaka@tcp(192.168.1.226:3306)/dzz_online?charset=utf8&parseTime=true&loc=Local&timeout=30s",
|
||||
"GameDBMaxOpenConns": 10,
|
||||
"GameDBMaxIdleConns": 5
|
||||
},
|
||||
{
|
||||
"AppId": "DZZ",
|
||||
"IfRecordMessage": true
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user