mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-28 05:12:32 +08:00
更新2.1.2版本,优化部门、角色权限,增加上下级关系;增加登录、系统、短信日志;优化省市区编码
This commit is contained in:
@@ -10,20 +10,32 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/hggen"
|
||||
"hotgo/internal/library/location"
|
||||
"hotgo/internal/library/queue"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/charset"
|
||||
"hotgo/utility/simple"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
if _, err := g.Cfg().Get(ctx, "hotgo.debug"); err != nil {
|
||||
_, err := g.Cfg().Get(ctx, "hotgo.debug")
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, "配置读取异常:", err, "\r\n你确定 config/config.yaml 文件存在且格式正确吗?\r\n")
|
||||
return
|
||||
}
|
||||
//g.SetDebug(debug.Bool())
|
||||
|
||||
// 默认上海时区
|
||||
if err := gtime.SetTimeZone("Asia/Shanghai"); err != nil {
|
||||
g.Log().Fatalf(ctx, "时区设置异常err:%+v", err)
|
||||
@@ -33,12 +45,15 @@ func Init(ctx context.Context) {
|
||||
RootPtah, _ = os.Getwd()
|
||||
fmt.Printf("欢迎使用HotGo!\r\n当前运行环境:%v, 运行根路径为:%v \r\nHotGo版本:v%v, gf版本:%v \n", SysType, RootPtah, consts.VersionApp, gf.VERSION)
|
||||
|
||||
g.Log().SetHandlers(LoggingServeLogHandler)
|
||||
|
||||
setOrmCacheAdapter()
|
||||
|
||||
service.SysBlacklist().Load(ctx)
|
||||
|
||||
startMonitor(ctx)
|
||||
|
||||
hggen.InIt(ctx)
|
||||
|
||||
}
|
||||
|
||||
func startMonitor(ctx context.Context) {
|
||||
@@ -62,3 +77,47 @@ func setOrmCacheAdapter() {
|
||||
redisCache := gcache.NewAdapterRedis(g.Redis())
|
||||
g.DB().GetCache().SetAdapter(redisCache)
|
||||
}
|
||||
|
||||
func LoggingServeLogHandler(ctx context.Context, in *glog.HandlerInput) {
|
||||
in.Next(ctx)
|
||||
|
||||
conf, err := service.SysConfig().GetLoadServeLog(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !conf.Switch {
|
||||
return
|
||||
}
|
||||
|
||||
if in.LevelFormat == "" || !gstr.InArray(conf.LevelFormat, in.LevelFormat) {
|
||||
return
|
||||
}
|
||||
|
||||
var data entity.SysServeLog
|
||||
data.TraceId = gctx.CtxId(ctx)
|
||||
data.LevelFormat = in.LevelFormat
|
||||
data.Content = in.Content
|
||||
data.Stack = gjson.New(charset.ParseStack(in.Stack))
|
||||
data.Line = in.CallerPath
|
||||
data.TriggerNs = in.Time.UnixNano()
|
||||
data.Status = consts.StatusEnabled
|
||||
|
||||
if data.Stack.IsNil() {
|
||||
data.Stack = gjson.New(consts.NilJsonToString)
|
||||
}
|
||||
|
||||
if gstr.Contains(in.Content, `exception recovered`) {
|
||||
data.LevelFormat = "PANI"
|
||||
}
|
||||
|
||||
if conf.Queue {
|
||||
err = queue.Push(consts.QueueServeLogTopic, data)
|
||||
} else {
|
||||
err = service.SysServeLog().RealWrite(ctx, data)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
g.Log().Printf(ctx, "LoggingServeLogHandler err:%+v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -18,4 +18,6 @@ var (
|
||||
SysType = runtime.GOOS
|
||||
// MonitorData 监控数据
|
||||
MonitorData model.MonitorData
|
||||
// Blacklists 黑名单列表
|
||||
Blacklists map[string]struct{}
|
||||
)
|
||||
|
Reference in New Issue
Block a user