diff --git a/app.go b/app.go index 696cc63..c2005f1 100644 --- a/app.go +++ b/app.go @@ -61,11 +61,11 @@ func (this *app) init(userApp UserApp) { this.userApp = userApp this.nowTime = time.Now() atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano()) - _timer = &Timer{} + _timer = new(timer) _timer.init() - _sysLog = new(SysLog_) + _sysLog = new(sysLog) _sysLog.init() - _tgLog = new(TGLog_) + _tgLog = new(tgLog) _tgLog.init() _dbFilter = new(dbFilter) _dbFilter.init() @@ -73,7 +73,7 @@ func (this *app) init(userApp UserApp) { _goStyleDb.init(GO_STYLE_DB) _jsStyleDb = new(dbPool) _jsStyleDb.init(JS_STYLE_DB) - _httpCliMgr = new(HttpCliMgr) + _httpCliMgr = new(httpCliMgr) _httpCliMgr.init() { tmpNodeId, tmpInstanceId := parseArgs() diff --git a/export.go b/export.go index 0fb8198..3797b02 100644 --- a/export.go +++ b/export.go @@ -1,10 +1,10 @@ package f5 var _app *app -var _timer *Timer -var _sysLog *SysLog_ -var _tgLog *TGLog_ -var _httpCliMgr *HttpCliMgr +var _timer *timer +var _sysLog *sysLog +var _tgLog *tgLog +var _httpCliMgr *httpCliMgr var _dbFilter *dbFilter var _goStyleDb *dbPool var _jsStyleDb *dbPool @@ -13,19 +13,19 @@ func GetApp() App { return _app } -func GetTimer() *Timer { +func GetTimer() *timer { return _timer } -func GetSysLog() *SysLog_ { +func GetSysLog() *sysLog { return _sysLog } -func GetTgLog() *TGLog_ { +func GetTgLog() *tgLog { return _tgLog } -func GetHttpCliMgr() *HttpCliMgr { +func GetHttpCliMgr() *httpCliMgr { return _httpCliMgr } diff --git a/httpclimgr.go b/httpclimgr.go index 27c5910..3ead7f0 100644 --- a/httpclimgr.go +++ b/httpclimgr.go @@ -32,11 +32,11 @@ type httpCliResponse struct { isTimeOut bool } -type HttpCliMgr struct { +type httpCliMgr struct { } -func (this *HttpCliMgr) init() { +func (this *httpCliMgr) init() { _app.RegisterIMMsgHandle( IM_HTTP_CLI_MGR_RESPONSE, func (args q5.Args) { @@ -46,10 +46,10 @@ func (this *HttpCliMgr) init() { }) } -func (this *HttpCliMgr) unInit() { +func (this *httpCliMgr) unInit() { } -func (this *HttpCliMgr) SendGoStyleRequest( +func (this *httpCliMgr) SendGoStyleRequest( url string, params map[string]string, cb func (HttpCliResponse)) { this.internalSendRequest( @@ -60,7 +60,7 @@ func (this *HttpCliMgr) SendGoStyleRequest( cb) } -func (this *HttpCliMgr) SendJsStyleRequest( +func (this *httpCliMgr) SendJsStyleRequest( url string, params map[string]string, cb func (HttpCliResponse)) { this.internalSendRequest( @@ -71,7 +71,7 @@ func (this *HttpCliMgr) SendJsStyleRequest( cb) } -func (this *HttpCliMgr) SendQuickChannelGoStyleRequest( +func (this *httpCliMgr) SendQuickChannelGoStyleRequest( url string, params map[string]string, cb func (HttpCliResponse)) { this.internalSendRequest( @@ -82,7 +82,7 @@ func (this *HttpCliMgr) SendQuickChannelGoStyleRequest( cb) } -func (this *HttpCliMgr) SendQuickChannelJsStyleRequest( +func (this *httpCliMgr) SendQuickChannelJsStyleRequest( url string, params map[string]string, cb func (HttpCliResponse)) { this.internalSendRequest( @@ -93,15 +93,15 @@ func (this *HttpCliMgr) SendQuickChannelJsStyleRequest( cb) } -func (this *HttpCliMgr) internalSendRequest( +func (this *httpCliMgr) internalSendRequest( style int32, channel int32, url string, params map[string]string, cb func (HttpCliResponse)) { if !(style == GO_STYLE_REQUEST || style == JS_STYLE_REQUEST) { - panic("HttpCliMgr sytel error") + panic("httpCliMgr sytel error") } if !(channel == NORMAL_CHANNEL || channel == QUICK_CHANNEL) { - panic("HttpCliMgr channel error") + panic("httpCliMgr channel error") } doFunc := func() { data, err := q5.HttpGet(url, params) diff --git a/syslog.go b/syslog.go index e166699..9d5b8fd 100644 --- a/syslog.go +++ b/syslog.go @@ -22,81 +22,81 @@ const ( SYS_LOG_FILENAME = "log_%d_%s.log" ) -type LogMsgNode struct { +type logMsgNode struct { category int32 logMsg string - next *LogMsgNode + next *logMsgNode } -type SysLog_ struct { +type sysLog struct { logLevel int32 - topNode *LogMsgNode - botNode *LogMsgNode + topNode *logMsgNode + botNode *logMsgNode msgMutex sync.Mutex chGoSaveExit chan int } -func (this *SysLog_) init() { +func (this *sysLog) init() { this.chGoSaveExit = make(chan int) go this.goSaveToFile() } -func (this *SysLog_) unInit() { +func (this *sysLog) unInit() { this.chGoSaveExit <- 1 } -func (this *SysLog_) Emergency(format string, args ...interface{}) { +func (this *sysLog) Emergency(format string, args ...interface{}) { if this.logLevel > LOG_EMERGENCY { return } this.addLog(LOG_EMERGENCY, "[EMERGENCY]", format, args...) } -func (this *SysLog_) Alert(format string, args ...interface{}) { +func (this *sysLog) Alert(format string, args ...interface{}) { if this.logLevel > LOG_ALERT { return } this.addLog(LOG_ALERT, "[ALERT]", format, args...) } -func (this *SysLog_) Error(format string, args ...interface{}) { +func (this *sysLog) Error(format string, args ...interface{}) { if this.logLevel > LOG_ERROR { return } this.addLog(LOG_ERROR, "[ERROR]", format, args...) } -func (this *SysLog_) Warning(format string, args ...interface{}) { +func (this *sysLog) Warning(format string, args ...interface{}) { if this.logLevel > LOG_WARNING { return } this.addLog(LOG_WARNING, "[WARNING]", format, args...) } -func (this *SysLog_) Notice(format string, args ...interface{}) { +func (this *sysLog) Notice(format string, args ...interface{}) { if this.logLevel > LOG_NOTICE { return } this.addLog(LOG_NOTICE, "[NOTICE]", format, args...) } -func (this *SysLog_) Info(format string, args ...interface{}) { +func (this *sysLog) Info(format string, args ...interface{}) { if this.logLevel > LOG_INFO { return } this.addLog(LOG_INFO, "[INFO]", format, args...) } -func (this *SysLog_) Debug(format string, args ...interface{}) { +func (this *sysLog) Debug(format string, args ...interface{}) { if this.logLevel > LOG_DEBUG { return } this.addLog(LOG_DEBUG, "[DEBUG]", format, args...) } -func (this *SysLog_) addLog(category int32, prefixStr string, +func (this *sysLog) addLog(category int32, prefixStr string, format string, args ...interface{}) { - p := &LogMsgNode{} + p := &logMsgNode{} p.category = category p.logMsg = time.Now().Format("2006-01-02 15:04:05") + prefixStr + " " + @@ -115,8 +115,8 @@ func (this *SysLog_) addLog(category int32, prefixStr string, } } -func (this *SysLog_) goSaveToFile() { - var workNode *LogMsgNode +func (this *sysLog) goSaveToFile() { + var workNode *logMsgNode for { select { case <-this.chGoSaveExit: diff --git a/tglog.go b/tglog.go index c8a8d81..e849f14 100644 --- a/tglog.go +++ b/tglog.go @@ -1,61 +1,64 @@ package f5 -//import "os" -//import "fmt" -import "sync" -//import "time" -//import "q5" +import ( + "q5" + "os" + "sync" + "fmt" + "time" +) const TGLOG_ROOT = "/data/logs/%s/upload/" const POLY_TGLOG_ROOT = "/data/logs/%s/%d/upload/" const TGLOG_FILENAME = "log_%d_%s.log" -type TGLogMsgNode struct { +type tgLogMsgNode struct { gameId int32 jsonStr string - next *TGLogMsgNode + next *tgLogMsgNode } -type TGLog_ struct { +type tgLog struct { isPolyLog bool - topNode *TGLogMsgNode - botNode *TGLogMsgNode + topNode *tgLogMsgNode + botNode *tgLogMsgNode msgMutex sync.Mutex chGoSaveExit chan int } -func (this *TGLog_) init() { +func (this *tgLog) init() { this.chGoSaveExit = make(chan int) //go this.goSaveToFile() } -func (this *TGLog_) unInit() { +func (this *tgLog) unInit() { this.chGoSaveExit <- 1 } -func (this *TGLog_) SetPolyLog(isPolyLog bool) { +func (this *tgLog) SetPolyLog(isPolyLog bool) { this.isPolyLog = isPolyLog } -/* -func (this *TGLog_) AddTrackLog( +func (this *tgLog) AddTrackLog( gameId int32, accountId string, remoteAddr string, logClass1 int32, logClass2 int32, - prop *q5.XObject) { - eventName := fmt.Sprintf("event_%d_%d", logClass1, logClass2) - this.AddTrackLogEx(gameId, accountId, remoteAddr, eventName, prop) + //prop *q5.XObject) { + ) { + //eventName := fmt.Sprintf("event_%d_%d", logClass1, logClass2) + //this.AddTrackLogEx(gameId, accountId, remoteAddr, eventName, prop) } -func (this *TGLog_) AddTrackLogEx( +func (this *tgLog) AddTrackLogEx( gameId int32, accountId string, remoteAddr string, eventName string, - prop *q5.XObject) { - xobj := q5.NewMxoObject() + //prop *q5.XObject) { +) { + /*xobj := q5.NewMxoObject() xobj.SetXValue("#account_id", q5.NewXString(accountId)) xobj.SetXValue("#type", q5.NewXString("track")) xobj.SetXValue("#time", q5.NewXString(time.Now().Format("2006-01-02 15:04:05"))) @@ -64,7 +67,7 @@ func (this *TGLog_) AddTrackLogEx( xobj.SetXObject("properties", prop) - p := new(TGLogMsgNode) + p := new(tgLogMsgNode) p.gameId = gameId p.jsonStr = xobj.ToJsonStr() this.msgMutex.Lock() @@ -76,11 +79,11 @@ func (this *TGLog_) AddTrackLogEx( this.topNode = p this.botNode = p } -//} -*/ - /* -func (this *TGLog_) goSaveToFile() { - var workNode *TGLogMsgNode + */ +} + +func (this *tgLog) goSaveToFile() { + var workNode *tgLogMsgNode for { select { case <-this.chGoSaveExit: @@ -105,21 +108,19 @@ func (this *TGLog_) goSaveToFile() { } } -func (this *TGLog_) getLogFile(gameId int32) *os.File { +func (this *tgLog) getLogFile(gameId int32) *os.File { fileName := fmt.Sprintf(TGLOG_FILENAME, os.Getpid(), time.Now().Format("20060102")) logDir := "" if this.isPolyLog { - logDir = fmt.Sprintf(POLY_TGLOG_ROOT, App.GetPkgName(), gameId) + logDir = fmt.Sprintf(POLY_TGLOG_ROOT, _app.GetPkgName(), gameId) } else { - logDir = fmt.Sprintf(TGLOG_ROOT, App.GetPkgName()) + logDir = fmt.Sprintf(TGLOG_ROOT, _app.GetPkgName()) } q5.ForceCreateDir(logDir) if f, err := os.OpenFile(logDir + fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666); err == nil { return f } else { - SysLog().Warning("TGLog.goSaveToFile err:%s", err) + _sysLog.Warning("tgLog.goSaveToFile err:%s", err) return nil } } - - */ diff --git a/timer.go b/timer.go index b2a7f8b..38f06fd 100644 --- a/timer.go +++ b/timer.go @@ -12,13 +12,13 @@ type TimerAttacher struct { *q5.XTimerAttacher } -type Timer struct { - timer *q5.XTimer +type timer struct { + base *q5.XTimer } -func (this *Timer) init() { - this.timer = new(q5.XTimer) - this.timer.Init( +func (this *timer) init() { + this.base = new(q5.XTimer) + this.base.Init( func (context interface{}) int64 { return q5.GetTickCount() }, @@ -27,73 +27,73 @@ func (this *Timer) init() { 5000) } -func (this *Timer) update() { - this.timer.Update() +func (this *timer) update() { + this.base.Update() } -func (this *Timer) unInit() { - this.timer.UnInit() - this.timer = nil +func (this *timer) unInit() { + this.base.UnInit() + this.base = nil } -func (this *Timer) NewTimerAttacher() *TimerAttacher { +func (this *timer) NewTimerAttacher() *TimerAttacher { ac := TimerAttacher{} - ac.XTimerAttacher = this.timer.NewTimerAttacher() + ac.XTimerAttacher = this.base.NewTimerAttacher() return &ac } -func (this *Timer) SetTimeout(expireTime int32, cb q5.TimerCb) { - this.timer.SetTimeout(expireTime, cb) +func (this *timer) SetTimeout(expireTime int32, cb q5.TimerCb) { + this.base.SetTimeout(expireTime, cb) } -func (this *Timer) SetTimeoutEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) { - this.timer.SetTimeoutEx(expireTime, cb, ac.XTimerAttacher) +func (this *timer) SetTimeoutEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) { + this.base.SetTimeoutEx(expireTime, cb, ac.XTimerAttacher) } -func (this *Timer) SetTimeoutWp(expireTime int32, cb q5.TimerCb) *TimerWp { +func (this *timer) SetTimeoutWp(expireTime int32, cb q5.TimerCb) *TimerWp { wp := TimerWp{} - wp.XTimerWp = this.timer.SetTimeoutWp(expireTime, cb) + wp.XTimerWp = this.base.SetTimeoutWp(expireTime, cb) return &wp } -func (this *Timer) SetTimeoutExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp { +func (this *timer) SetTimeoutExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp { wp := TimerWp{} - wp.XTimerWp = this.timer.SetTimeoutExWp(expireTime, cb, ac.XTimerAttacher) + wp.XTimerWp = this.base.SetTimeoutExWp(expireTime, cb, ac.XTimerAttacher) return &wp } -func (this *Timer) SetInterval(expireTime int32, cb q5.TimerCb) { - this.timer.SetInterval(expireTime, cb) +func (this *timer) SetInterval(expireTime int32, cb q5.TimerCb) { + this.base.SetInterval(expireTime, cb) } -func (this *Timer) SetIntervalEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) { - this.timer.SetIntervalEx(expireTime, cb, ac.XTimerAttacher) +func (this *timer) SetIntervalEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) { + this.base.SetIntervalEx(expireTime, cb, ac.XTimerAttacher) } -func (this *Timer) SetIntervalWp(expireTime int32, cb q5.TimerCb) *TimerWp { +func (this *timer) SetIntervalWp(expireTime int32, cb q5.TimerCb) *TimerWp { wp := TimerWp{} - wp.XTimerWp = this.timer.SetIntervalWp(expireTime, cb) + wp.XTimerWp = this.base.SetIntervalWp(expireTime, cb) return &wp } -func (this *Timer) SetIntervalExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp { +func (this *timer) SetIntervalExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp { wp := TimerWp{} - wp.XTimerWp = this.timer.SetIntervalExWp(expireTime, cb, ac.XTimerAttacher) + wp.XTimerWp = this.base.SetIntervalExWp(expireTime, cb, ac.XTimerAttacher) return &wp } -func (this *Timer) GetIdleTime() int64 { - return this.timer.GetIdleTime() +func (this *timer) GetIdleTime() int64 { + return this.base.GetIdleTime() } -func (this *Timer) ModifyTimer(timerWp *TimerWp, expireTime int32) { - this.timer.ModifyTimer(timerWp.XTimerWp, expireTime) +func (this *timer) ModifyTimer(timerWp *TimerWp, expireTime int32) { + this.base.ModifyTimer(timerWp.XTimerWp, expireTime) } -func (this *Timer) Delete(timerWp *TimerWp) { - this.timer.Delete(timerWp.XTimerWp) +func (this *timer) Delete(timerWp *TimerWp) { + this.base.Delete(timerWp.XTimerWp) } -func (this *Timer) GetRemainTime(timerWp *TimerWp) int64 { - return this.timer.GetRemainTime(timerWp.XTimerWp) +func (this *timer) GetRemainTime(timerWp *TimerWp) int64 { + return this.base.GetRemainTime(timerWp.XTimerWp) }