mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-12 12:13:51 +08:00
发布v2.15.1版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -13,17 +13,10 @@ import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/os/grpool"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/utility/encrypt"
|
||||
)
|
||||
|
||||
// AppName 应用名称
|
||||
func AppName(ctx context.Context) string {
|
||||
return g.Cfg().MustGet(ctx, "appName", "hotgo").String()
|
||||
}
|
||||
|
||||
// RouterPrefix 获取应用路由前缀
|
||||
func RouterPrefix(ctx context.Context, app string) string {
|
||||
return g.Cfg().MustGet(ctx, "router."+app+".prefix", "/"+app+"").String()
|
||||
@@ -35,7 +28,7 @@ func FilterMaskDemo(ctx context.Context, src g.Map) g.Map {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !g.Cfg().MustGet(ctx, "hotgo.isDemo", false).Bool() {
|
||||
if !IsDemo(ctx) {
|
||||
return src
|
||||
}
|
||||
|
||||
@@ -82,22 +75,14 @@ func CheckPassword(input, salt, hash string) (err error) {
|
||||
}
|
||||
|
||||
// SafeGo 安全的调用协程,遇到错误时输出错误日志而不是抛出panic
|
||||
func SafeGo(ctx context.Context, f func(ctx context.Context), lv ...interface{}) {
|
||||
var level = glog.LEVEL_ERRO
|
||||
if len(lv) > 0 {
|
||||
level = gconv.Int(lv[0])
|
||||
}
|
||||
|
||||
err := grpool.AddWithRecover(ctx, func(ctx context.Context) {
|
||||
f(ctx)
|
||||
}, func(ctx context.Context, err error) {
|
||||
func SafeGo(ctx context.Context, f func(ctx context.Context), lv ...int) {
|
||||
g.Go(ctx, f, func(ctx context.Context, err error) {
|
||||
var level = glog.LEVEL_ERRO
|
||||
if len(lv) > 0 {
|
||||
level = lv[0]
|
||||
}
|
||||
Logf(level, ctx, "SafeGo exec failed:%+v", err)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
Logf(level, ctx, "SafeGo AddWithRecover err:%+v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func Logf(level int, ctx context.Context, format string, v ...interface{}) {
|
||||
|
||||
Reference in New Issue
Block a user