Try to abstract the main part.
This commit is contained in:
@ -134,7 +134,7 @@ func (this *AlienService) PreviewOrDownload(
|
||||
}
|
||||
|
||||
//文件下载次数加一,为了加快访问速度,异步进行
|
||||
go util.SafeMethod(func() {
|
||||
go util.RunWithRecovery(func() {
|
||||
this.matterDao.TimesIncrement(uuid)
|
||||
})
|
||||
|
||||
|
@ -2,7 +2,7 @@ package rest
|
||||
|
||||
import (
|
||||
"github.com/eyebluecn/tank/code/config"
|
||||
"github.com/eyebluecn/tank/code/logger"
|
||||
"github.com/eyebluecn/tank/code/tool/inter"
|
||||
"github.com/eyebluecn/tank/code/tool/result"
|
||||
"github.com/eyebluecn/tank/code/tool/util"
|
||||
"net/http"
|
||||
@ -20,11 +20,11 @@ type IBean interface {
|
||||
}
|
||||
|
||||
type Bean struct {
|
||||
logger *logger.Logger
|
||||
logger inter.Logger
|
||||
}
|
||||
|
||||
func (this *Bean) Init() {
|
||||
this.logger = logger.LOGGER
|
||||
this.logger = inter.LOGGER
|
||||
}
|
||||
|
||||
func (this *Bean) Bootstrap() {
|
||||
@ -59,6 +59,7 @@ func (this *Bean) findUser(writer http.ResponseWriter, request *http.Request) *U
|
||||
}
|
||||
|
||||
if cacheItem == nil || cacheItem.Data() == nil {
|
||||
|
||||
this.logger.Warn("cache item中已经不存在了 ")
|
||||
return nil
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package rest
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/config"
|
||||
"github.com/eyebluecn/tank/code/logger"
|
||||
cache2 "github.com/eyebluecn/tank/code/tool/cache"
|
||||
"github.com/eyebluecn/tank/code/tool/inter"
|
||||
"github.com/jinzhu/gorm"
|
||||
"reflect"
|
||||
)
|
||||
@ -56,7 +56,7 @@ func (this *Context) OpenDb() {
|
||||
this.DB, err = gorm.Open("mysql", config.CONFIG.MysqlUrl)
|
||||
|
||||
if err != nil {
|
||||
logger.LOGGER.Panic("failed to connect mysql database")
|
||||
inter.LOGGER.Panic("failed to connect mysql database")
|
||||
}
|
||||
|
||||
//是否打开sql日志(在调试阶段可以打开,以方便查看执行的SQL)
|
||||
@ -68,7 +68,7 @@ func (this *Context) CloseDb() {
|
||||
if this.DB != nil {
|
||||
err := this.DB.Close()
|
||||
if err != nil {
|
||||
fmt.Println("关闭数据库连接出错", err)
|
||||
inter.LOGGER.Error("关闭数据库连接出错 %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,7 +83,7 @@ func (this *Context) registerBean(bean IBean) {
|
||||
|
||||
err := fmt.Sprintf("【%s】已经被注册了,跳过。", typeName)
|
||||
if _, ok := this.BeanMap[typeName]; ok {
|
||||
logger.LOGGER.Error(fmt.Sprintf(err))
|
||||
inter.LOGGER.Error(fmt.Sprintf(err))
|
||||
} else {
|
||||
this.BeanMap[typeName] = element
|
||||
|
||||
@ -95,7 +95,7 @@ func (this *Context) registerBean(bean IBean) {
|
||||
}
|
||||
|
||||
} else {
|
||||
logger.LOGGER.Panic("注册的【%s】不是Bean类型。", typeName)
|
||||
inter.LOGGER.Panic("注册的【%s】不是Bean类型。", typeName)
|
||||
}
|
||||
|
||||
}
|
||||
@ -165,7 +165,7 @@ func (this *Context) GetBean(bean IBean) IBean {
|
||||
if val, ok := this.BeanMap[typeName]; ok {
|
||||
return val
|
||||
} else {
|
||||
logger.LOGGER.Panic("【%s】没有注册。", typeName)
|
||||
inter.LOGGER.Panic("【%s】没有注册。", typeName)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func (this *DashboardService) Bootstrap() {
|
||||
this.logger.Info("[cron job] 每日00:05清洗离线数据")
|
||||
|
||||
//立即执行一次数据清洗任务
|
||||
go util.SafeMethod(this.etl)
|
||||
go util.RunWithRecovery(this.etl)
|
||||
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ func (this *FootprintService) Bootstrap() {
|
||||
this.logger.Info("[cron job] 每日00:10 删除8日之前的访问数据")
|
||||
|
||||
//立即执行一次数据清洗任务
|
||||
go util.SafeMethod(this.cleanOldData)
|
||||
go util.RunWithRecovery(this.cleanOldData)
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package rest
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/config"
|
||||
"github.com/eyebluecn/tank/code/logger"
|
||||
"github.com/eyebluecn/tank/code/tool/inter"
|
||||
"github.com/eyebluecn/tank/code/tool/result"
|
||||
"github.com/eyebluecn/tank/code/tool/util"
|
||||
"github.com/json-iterator/go"
|
||||
@ -72,7 +72,7 @@ func NewRouter() *Router {
|
||||
func (this *Router) GlobalPanicHandler(writer http.ResponseWriter, request *http.Request, startTime time.Time) {
|
||||
if err := recover(); err != nil {
|
||||
|
||||
logger.LOGGER.Error("错误: %v", err)
|
||||
inter.LOGGER.Error("错误: %v", err)
|
||||
|
||||
var webResult *result.WebResult = nil
|
||||
if value, ok := err.(string); ok {
|
||||
@ -108,7 +108,7 @@ func (this *Router) GlobalPanicHandler(writer http.ResponseWriter, request *http
|
||||
}
|
||||
|
||||
//错误情况记录。
|
||||
go util.SafeMethod(func() {
|
||||
go util.RunWithRecovery(func() {
|
||||
this.footprintService.Trace(writer, request, time.Now().Sub(startTime), false)
|
||||
})
|
||||
}
|
||||
@ -156,7 +156,7 @@ func (this *Router) ServeHTTP(writer http.ResponseWriter, request *http.Request)
|
||||
}
|
||||
|
||||
//正常的访问记录会落到这里。
|
||||
go util.SafeMethod(func() {
|
||||
go util.RunWithRecovery(func() {
|
||||
this.footprintService.Trace(writer, request, time.Now().Sub(startTime), true)
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user