diff --git a/server/internal/controller/admin/admin/monitor.go b/server/internal/controller/admin/admin/monitor.go index 702398a..c9510ee 100644 --- a/server/internal/controller/admin/admin/monitor.go +++ b/server/internal/controller/admin/admin/monitor.go @@ -103,7 +103,7 @@ func (c *cMonitor) UserOnlineList(ctx context.Context, req *monitor.UserOnlineLi return clients[i].FirstTime < clients[j].FirstTime }) - isDemo := g.Cfg().MustGet(ctx, "hotgo.isDemo", false).Bool() + isDemo := g.Cfg().MustGet(ctx, simple.AppName(ctx)+".isDemo", false).Bool() _, perPage, offset := form.CalPage(req.Page, req.PerPage) for k, v := range clients { diff --git a/server/internal/controller/websocket/handler/admin/monitor.go b/server/internal/controller/websocket/handler/admin/monitor.go index 33dfc77..c38feb3 100644 --- a/server/internal/controller/websocket/handler/admin/monitor.go +++ b/server/internal/controller/websocket/handler/admin/monitor.go @@ -7,6 +7,10 @@ package admin import ( "fmt" + "os" + "runtime" + "time" + "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/util/gconv" @@ -15,15 +19,14 @@ import ( "github.com/shirou/gopsutil/v3/host" "github.com/shirou/gopsutil/v3/mem" "github.com/shirou/gopsutil/v3/process" + "hotgo/internal/consts" "hotgo/internal/model" "hotgo/internal/service" "hotgo/internal/websocket" "hotgo/utility/file" "hotgo/utility/format" - "os" - "runtime" - "time" + "hotgo/utility/simple" ) var ( @@ -76,7 +79,7 @@ func (c *cMonitor) RunInfo(client *websocket.Client, req *websocket.WRequest) { "goSize": file.DirSize(pwd), } - isDemo := g.Cfg().MustGet(client.Context(), "hotgo.isDemo", false).Bool() + isDemo := g.Cfg().MustGet(client.Context(), simple.AppName(client.Context())+".isDemo", false).Bool() if isDemo { data["rootPath"] = consts.DemoTips data["pwd"] = consts.DemoTips diff --git a/server/internal/global/cluster.go b/server/internal/global/cluster.go index f1bda98..54a474c 100644 --- a/server/internal/global/cluster.go +++ b/server/internal/global/cluster.go @@ -13,11 +13,12 @@ import ( "hotgo/internal/library/hgrds/lock" "hotgo/internal/library/hgrds/pubsub" "hotgo/internal/service" + "hotgo/utility/simple" ) // SubscribeClusterSync 订阅集群同步,可以用来集中同步数据、状态等 func SubscribeClusterSync(ctx context.Context) { - isCluster := g.Cfg().MustGet(ctx, "hotgo.isCluster").Bool() + isCluster := g.Cfg().MustGet(ctx, simple.AppName(ctx)+".isCluster").Bool() if !isCluster { return } @@ -35,7 +36,7 @@ func SubscribeClusterSync(ctx context.Context) { // PublishClusterSync 推送集群同步消息,如果没有开启集群部署,则不进行推送 func PublishClusterSync(ctx context.Context, channel string, message interface{}) { - isCluster := g.Cfg().MustGet(ctx, "hotgo.isCluster").Bool() + isCluster := g.Cfg().MustGet(ctx, simple.AppName(ctx)+".isCluster").Bool() if !isCluster { return } diff --git a/server/internal/library/location/location.go b/server/internal/library/location/location.go index 04fd8a3..100a2c6 100644 --- a/server/internal/library/location/location.go +++ b/server/internal/library/location/location.go @@ -8,6 +8,12 @@ package location import ( "context" "fmt" + "io" + "net" + "net/http" + "strings" + "time" + "github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/encoding/gcharset" "github.com/gogf/gf/v2/frame/g" @@ -15,12 +21,9 @@ import ( "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" "github.com/kayon/iploc" + + "hotgo/utility/simple" "hotgo/utility/validate" - "io" - "net" - "net/http" - "strings" - "time" ) const ( @@ -141,7 +144,7 @@ func GetLocation(ctx context.Context, ip string) (data *IpLocationData, err erro return data1, nil } - mode := g.Cfg().MustGet(ctx, "hotgo.ipMethod", "cz88").String() + mode := g.Cfg().MustGet(ctx, simple.AppName(ctx)+".ipMethod", "cz88").String() switch mode { case "whois": data, err = WhoisLocation(ctx, ip) diff --git a/server/internal/logic/middleware/init.go b/server/internal/logic/middleware/init.go index a1d5215..ddaafc6 100644 --- a/server/internal/logic/middleware/init.go +++ b/server/internal/logic/middleware/init.go @@ -23,6 +23,7 @@ import ( "hotgo/internal/library/token" "hotgo/internal/model" "hotgo/internal/service" + "hotgo/utility/simple" "hotgo/utility/validate" "net/http" "strings" @@ -94,7 +95,7 @@ func (s *sMiddleware) CORS(r *ghttp.Request) { // DemoLimit 演示系統操作限制 func (s *sMiddleware) DemoLimit(r *ghttp.Request) { - isDemo := g.Cfg().MustGet(r.Context(), "hotgo.isDemo", false) + isDemo := g.Cfg().MustGet(r.Context(), simple.AppName(context.TODO())+".isDemo", false) if !isDemo.Bool() { r.Middleware.Next() return diff --git a/server/internal/logic/middleware/response.go b/server/internal/logic/middleware/response.go index f41d8b2..9a1d4fc 100644 --- a/server/internal/logic/middleware/response.go +++ b/server/internal/logic/middleware/response.go @@ -11,6 +11,7 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/util/gmeta" + "hotgo/internal/consts" "hotgo/internal/library/contexts" "hotgo/internal/library/response" @@ -73,7 +74,7 @@ func parseResponse(r *ghttp.Request) (code int, message string, resp interface{} } // 是否输出错误堆栈到页面 - if g.Cfg().MustGet(ctx, "hotgo.debug", true).Bool() { + if g.Cfg().MustGet(ctx, simple.AppName(ctx)+".debug", true).Bool() { message = gerror.Current(err).Error() if getContentType(r) == consts.HTTPContentTypeHtml { resp = charset.SerializeStack(err) diff --git a/server/internal/logic/sys/addons_config.go b/server/internal/logic/sys/addons_config.go index d36de7a..01d1843 100644 --- a/server/internal/logic/sys/addons_config.go +++ b/server/internal/logic/sys/addons_config.go @@ -17,6 +17,7 @@ import ( "hotgo/internal/model/entity" "hotgo/internal/model/input/sysin" "hotgo/internal/service" + "hotgo/utility/simple" ) var AddonsMaskDemoField []string @@ -55,7 +56,7 @@ func (s *sSysAddonsConfig) GetConfigByGroup(ctx context.Context, in *sysin.GetAd return nil, err } - isDemo := g.Cfg().MustGet(ctx, "hotgo.isDemo", false) + isDemo := g.Cfg().MustGet(ctx, simple.AppName(ctx)+".isDemo", false) if len(models) > 0 { res = new(sysin.GetAddonsConfigModel) res.List = make(g.Map, len(models)) diff --git a/server/internal/logic/sys/config.go b/server/internal/logic/sys/config.go index 291e2b8..833c788 100644 --- a/server/internal/logic/sys/config.go +++ b/server/internal/logic/sys/config.go @@ -194,13 +194,13 @@ func (s *sSysConfig) GetLoadToken(ctx context.Context) (conf *model.TokenConfig, // GetLoadLog 获取本地日志配置 func (s *sSysConfig) GetLoadLog(ctx context.Context) (conf *model.LogConfig, err error) { - err = g.Cfg().MustGet(ctx, "hotgo.log").Scan(&conf) + err = g.Cfg().MustGet(ctx, simple.AppName(ctx)+".log").Scan(&conf) return } // GetLoadServeLog 获取本地服务日志配置 func (s *sSysConfig) GetLoadServeLog(ctx context.Context) (conf *model.ServeLogConfig, err error) { - err = g.Cfg().MustGet(ctx, "hotgo.serveLog").Scan(&conf) + err = g.Cfg().MustGet(ctx, simple.AppName(ctx)+".serveLog").Scan(&conf) return } diff --git a/server/internal/logic/sys/log.go b/server/internal/logic/sys/log.go index a30b53d..34c1b32 100644 --- a/server/internal/logic/sys/log.go +++ b/server/internal/logic/sys/log.go @@ -241,7 +241,7 @@ func (s *sSysLog) View(ctx context.Context, in *sysin.LogViewInp) (res *sysin.Lo return } - if g.Cfg().MustGet(ctx, "hotgo.isDemo", false).Bool() { + if g.Cfg().MustGet(ctx, simple.AppName(ctx)+".isDemo", false).Bool() { res.HeaderData = gjson.New(`{ "none": [ "` + consts.DemoTips + `" @@ -310,7 +310,7 @@ func (s *sSysLog) List(ctx context.Context, in *sysin.LogListInp) (list []*sysin return } - isDemo := g.Cfg().MustGet(ctx, "hotgo.isDemo", false).Bool() + isDemo := g.Cfg().MustGet(ctx, simple.AppName(ctx)+"isDemo", false).Bool() for i := 0; i < len(list); i++ { // 管理员 if list[i].AppId == consts.AppAdmin { diff --git a/server/internal/logic/view/view.go b/server/internal/logic/view/view.go index dd86ad0..99bcffc 100644 --- a/server/internal/logic/view/view.go +++ b/server/internal/logic/view/view.go @@ -7,9 +7,11 @@ package view import ( "context" + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/util/gconv" + "hotgo/internal/model" "hotgo/internal/service" "hotgo/utility/charset" @@ -95,7 +97,7 @@ func (s *sView) Error(ctx context.Context, err error) { ) // 是否输出错误堆栈到页面 - if g.Cfg().MustGet(ctx, "hotgo.debug", true).Bool() { + if g.Cfg().MustGet(ctx, simple.AppName(ctx)+".debug", true).Bool() { stack = charset.SerializeStack(err) } diff --git a/server/utility/simple/simple.go b/server/utility/simple/simple.go index 9656aed..fd32083 100644 --- a/server/utility/simple/simple.go +++ b/server/utility/simple/simple.go @@ -7,6 +7,7 @@ package simple import ( "context" + "github.com/gogf/gf/v2/crypto/gmd5" "github.com/gogf/gf/v2/encoding/gbase64" "github.com/gogf/gf/v2/errors/gerror" @@ -15,6 +16,7 @@ import ( "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" ) @@ -35,7 +37,7 @@ func FilterMaskDemo(ctx context.Context, src g.Map) g.Map { return nil } - if !g.Cfg().MustGet(ctx, "hotgo.isDemo", false).Bool() { + if !g.Cfg().MustGet(ctx, AppName(ctx)+".isDemo", false).Bool() { return src }