diff --git a/server/internal/controller/admin/admin/monitor.go b/server/internal/controller/admin/admin/monitor.go index ac68e6a..08388c9 100644 --- a/server/internal/controller/admin/admin/monitor.go +++ b/server/internal/controller/admin/admin/monitor.go @@ -7,17 +7,19 @@ package admin import ( "context" + "sort" + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/text/gstr" + "hotgo/api/admin/monitor" "hotgo/internal/consts" "hotgo/internal/model/input/form" "hotgo/internal/websocket" "hotgo/utility/simple" "hotgo/utility/useragent" - "sort" ) // Monitor 监控 @@ -93,7 +95,7 @@ func (c *cMonitor) OnlineList(ctx context.Context, req *monitor.OnlineListReq) ( res.PerPage = req.PerPage sort.Sort(monitor.OnlineModels(clients)) - isDemo := g.Cfg().MustGet(ctx, "hotgo.isDemo", false).Bool() + isDemo := g.Cfg().MustGet(ctx, simple.AppName(ctx)+".isDemo", false).Bool() _, perPage, offset := form.CalPage(ctx, 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 48c6368..2014385 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/library/casbin/enforcer.go b/server/internal/library/casbin/enforcer.go index d2f6cf3..d16d3e7 100644 --- a/server/internal/library/casbin/enforcer.go +++ b/server/internal/library/casbin/enforcer.go @@ -7,12 +7,15 @@ package casbin import ( "context" + "net/http" + "strings" + "github.com/casbin/casbin/v2" _ "github.com/gogf/gf/contrib/drivers/mysql/v2" "github.com/gogf/gf/v2/frame/g" + "hotgo/internal/consts" - "net/http" - "strings" + "hotgo/utility/simple" ) const ( @@ -55,7 +58,7 @@ func loadPermissions(ctx context.Context) { rules [][]string polices []*Policy err error - superRoleKey = g.Cfg().MustGet(ctx, "hotgo.admin.superRoleKey") + superRoleKey = g.Cfg().MustGet(ctx, simple.AppName(ctx)+".admin.superRoleKey") ) err = g.Model("hg_admin_role r"). 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/admin/member.go b/server/internal/logic/admin/member.go index 85d70d2..c5b2cd0 100644 --- a/server/internal/logic/admin/member.go +++ b/server/internal/logic/admin/member.go @@ -8,6 +8,7 @@ package admin import ( "context" "fmt" + "github.com/gogf/gf/v2/crypto/gmd5" "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/errors/gerror" @@ -16,6 +17,7 @@ import ( "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/grand" + "hotgo/internal/consts" "hotgo/internal/dao" "hotgo/internal/library/contexts" @@ -26,6 +28,7 @@ import ( "hotgo/internal/model/input/adminin" "hotgo/internal/model/input/sysin" "hotgo/internal/service" + "hotgo/utility/simple" "hotgo/utility/tree" "hotgo/utility/validate" ) @@ -718,7 +721,7 @@ func (s *sAdminMember) Select(ctx context.Context, in adminin.MemberSelectInp) ( // VerifySuperId 验证是否为超管 func (s *sAdminMember) VerifySuperId(ctx context.Context, verifyId int64) bool { - for _, id := range g.Cfg().MustGet(ctx, "hotgo.admin.superIds").Int64s() { + for _, id := range g.Cfg().MustGet(ctx, simple.AppName(ctx)+".admin.superIds").Int64s() { if id == verifyId { return true } diff --git a/server/internal/logic/admin/role.go b/server/internal/logic/admin/role.go index efe9186..05ddf48 100644 --- a/server/internal/logic/admin/role.go +++ b/server/internal/logic/admin/role.go @@ -7,10 +7,13 @@ package admin import ( "context" + "sort" + "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" + "hotgo/internal/consts" "hotgo/internal/dao" "hotgo/internal/library/casbin" @@ -21,8 +24,8 @@ import ( "hotgo/internal/model/input/form" "hotgo/internal/service" "hotgo/utility/convert" + "hotgo/utility/simple" "hotgo/utility/tree" - "sort" ) type sAdminRole struct{} @@ -39,7 +42,7 @@ func init() { func (s *sAdminRole) Verify(ctx context.Context, path, method string) bool { var ( user = contexts.Get(ctx).User - sk = g.Cfg().MustGet(ctx, "hotgo.admin.superRoleKey") + sk = g.Cfg().MustGet(ctx, simple.AppName(ctx)+".admin.superRoleKey") err error ) @@ -272,7 +275,7 @@ func (s *sAdminRole) DataScopeSelect() (res form.Selects) { func (s *sAdminRole) DataScopeEdit(ctx context.Context, in *adminin.DataScopeEditInp) (err error) { var ( models *entity.AdminRole - sk = g.Cfg().MustGet(ctx, "hotgo.admin.superRoleKey") + sk = g.Cfg().MustGet(ctx, simple.AppName(ctx)+".admin.superRoleKey") ) if err = dao.AdminRole.Ctx(ctx).Where("id", in.Id).Scan(&models); err != nil { diff --git a/server/internal/logic/middleware/init.go b/server/internal/logic/middleware/init.go index 9f12804..e8134d3 100644 --- a/server/internal/logic/middleware/init.go +++ b/server/internal/logic/middleware/init.go @@ -8,6 +8,9 @@ package middleware import ( "context" "fmt" + "net/http" + "strings" + "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/frame/g" @@ -16,6 +19,7 @@ import ( "github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/text/gstr" "go.opentelemetry.io/otel/attribute" + "hotgo/internal/consts" "hotgo/internal/global" "hotgo/internal/library/addons" @@ -24,9 +28,8 @@ import ( "hotgo/internal/library/token" "hotgo/internal/model" "hotgo/internal/service" + "hotgo/utility/simple" "hotgo/utility/validate" - "net/http" - "strings" ) type sMiddleware struct { @@ -92,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(r.Context())+".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 3388061..55c404a 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" @@ -75,7 +76,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 edad31d..d6f0e86 100644 --- a/server/internal/logic/sys/addons_config.go +++ b/server/internal/logic/sys/addons_config.go @@ -7,16 +7,19 @@ package sys import ( "context" + "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/text/gstr" + "hotgo/internal/consts" "hotgo/internal/dao" "hotgo/internal/model/entity" "hotgo/internal/model/input/sysin" "hotgo/internal/service" + "hotgo/utility/simple" ) var AddonsMaskDemoField []string @@ -55,7 +58,7 @@ func (s *sSysAddonsConfig) GetConfigByGroup(ctx context.Context, in sysin.GetAdd 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)) @@ -112,19 +115,19 @@ func (s *sSysAddonsConfig) UpdateConfigByGroup(ctx context.Context, in sysin.Upd row := s.getConfigByKey(k, models) // 新增 if row == nil { - //row.Id = 0 - //row.Key = k - //row.Value = gconv.String(v) - //row.Group = in.Group - //row.Status = consts.StatusEnabled - //row.CreatedAt = gtime.Now() - //row.UpdatedAt = gtime.Now() - //_, err := dao.SysAddonsConfig.Ctx(ctx).Data(row).Insert() - //if err != nil { + // row.Id = 0 + // row.Key = k + // row.Value = gconv.String(v) + // row.Group = in.Group + // row.Status = consts.StatusEnabled + // row.CreatedAt = gtime.Now() + // row.UpdatedAt = gtime.Now() + // _, err := dao.SysAddonsConfig.Ctx(ctx).Data(row).Insert() + // if err != nil { // err = gerror.Wrap(err, consts.ErrorORM) // return err - //} - //continue + // } + // continue return gerror.Newf("暂不支持从前台添加变量,请先在数据库表[%v]中配置变量:%v", dao.SysAddonsConfig.Table(), k) } diff --git a/server/internal/logic/sys/config.go b/server/internal/logic/sys/config.go index 428c9b1..a8b0255 100644 --- a/server/internal/logic/sys/config.go +++ b/server/internal/logic/sys/config.go @@ -8,11 +8,13 @@ package sys import ( "context" "fmt" + "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/util/gconv" + "hotgo/internal/consts" "hotgo/internal/dao" "hotgo/internal/library/payment" @@ -174,13 +176,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 } @@ -242,19 +244,19 @@ func (s *sSysConfig) UpdateConfigByGroup(ctx context.Context, in sysin.UpdateCon row := s.getConfigByKey(k, models) // 新增 if row == nil { - //row.Id = 0 - //row.Key = k - //row.Value = gconv.String(v) - //row.Group = in.Group - //row.Status = consts.StatusEnabled - //row.CreatedAt = gtime.Now() - //row.UpdatedAt = gtime.Now() - //_, err := dao.SysConfig.Ctx(ctx).Data(row).Insert() - //if err != nil { + // row.Id = 0 + // row.Key = k + // row.Value = gconv.String(v) + // row.Group = in.Group + // row.Status = consts.StatusEnabled + // row.CreatedAt = gtime.Now() + // row.UpdatedAt = gtime.Now() + // _, err := dao.SysConfig.Ctx(ctx).Data(row).Insert() + // if err != nil { // err = gerror.Wrap(err, consts.ErrorORM) // return err - //} - //continue + // } + // continue err = gerror.Newf("暂不支持从前台添加变量,请先在数据库表[%v]中配置变量:%v", dao.SysConfig.Table(), k) return } diff --git a/server/internal/logic/sys/log.go b/server/internal/logic/sys/log.go index f18a0af..4b0de6e 100644 --- a/server/internal/logic/sys/log.go +++ b/server/internal/logic/sys/log.go @@ -8,6 +8,7 @@ package sys import ( "context" "encoding/json" + "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" @@ -16,6 +17,7 @@ import ( "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" + "hotgo/internal/consts" "hotgo/internal/dao" "hotgo/internal/library/contexts" @@ -241,7 +243,7 @@ func (s *sSysLog) View(ctx context.Context, in sysin.LogViewInp) (res *sysin.Log 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 + `" @@ -317,7 +319,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 { @@ -329,25 +331,25 @@ func (s *sSysLog) List(ctx context.Context, in sysin.LogListInp) (list []*sysin. list[i].MemberName = memberName.String() } - //// 接口 - //if list[i].AppId == consts.AppApi { + // // 接口 + // if list[i].AppId == consts.AppApi { // //memberName, err = dao.Member.Ctx(ctx).Fields("realname").Where("id", res.List[i].MemberId).Value() // //if err != nil { // // err = gerror.Wrap(err, consts.ErrorORM) // // return nil, err // //} - //} + // } if list[i].MemberName == "" { list[i].MemberName = "游客" } - //// 获取省市编码对应的地区名称 - //region, err := dao.SysProvinces.GetRegion(ctx, list[i].ProvinceId, list[i].CityId) - //if err != nil { + // // 获取省市编码对应的地区名称 + // region, err := dao.SysProvinces.GetRegion(ctx, list[i].ProvinceId, list[i].CityId) + // if err != nil { // return list, totalCount, err - //} - //list[i].Region = region + // } + // list[i].Region = region // 截取请求url路径 if gstr.Contains(list[i].Url, "?") { 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/internal/model/input/form/base.go b/server/internal/model/input/form/base.go index df6b642..676f53e 100644 --- a/server/internal/model/input/form/base.go +++ b/server/internal/model/input/form/base.go @@ -7,8 +7,11 @@ package form import ( "context" + "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/util/gconv" + + "hotgo/utility/simple" ) var ( @@ -21,7 +24,7 @@ func DefaultPageSize(ctx context.Context) int { if pageSize > 0 { return pageSize } - pageSize = g.Cfg().MustGet(ctx, "hotgo.admin.defaultPageSize", 10).Int() + pageSize = g.Cfg().MustGet(ctx, simple.AppName(ctx)+".admin.defaultPageSize", 10).Int() if pageSize <= 0 { pageSize = 10 } @@ -33,7 +36,7 @@ func DefaultPage(ctx context.Context) int { if page > 0 { return page } - page = g.Cfg().MustGet(ctx, "hotgo.admin.defaultPage", 1).Int() + page = g.Cfg().MustGet(ctx, simple.AppName(ctx)+".admin.defaultPage", 1).Int() if page <= 0 { page = 1 } @@ -118,7 +121,7 @@ type SelectInt64 struct { // DefaultMaxSort 默认最大排序 func DefaultMaxSort(ctx context.Context, baseSort int) int { - return baseSort + g.Cfg().MustGet(ctx, "hotgo.admin.maxSortIncrement", 10).Int() + return baseSort + g.Cfg().MustGet(ctx, simple.AppName(ctx)+".admin.maxSortIncrement", 10).Int() } // AvatarGroup 头像组 diff --git a/server/utility/simple/simple.go b/server/utility/simple/simple.go index ab91d9d..752f765 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 }