This commit is contained in:
孟帅
2024-04-22 23:08:40 +08:00
parent 82483bd7b9
commit e144b12580
445 changed files with 17457 additions and 6708 deletions

View File

@@ -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{}) {