Merge remote-tracking branch 'remotes/github/pr/37' into v2.0.0

# Conflicts:
#	server/internal/controller/admin/admin/monitor.go
#	server/internal/library/casbin/enforcer.go
#	server/internal/logic/admin/member.go
#	server/internal/logic/admin/role.go
#	server/internal/logic/middleware/init.go
#	server/internal/logic/sys/addons_config.go
#	server/internal/logic/sys/config.go
#	server/internal/logic/sys/log.go
#	server/internal/model/input/form/base.go
This commit is contained in:
Kevin 2023-10-06 17:44:15 +08:00
commit 98dc76f972
11 changed files with 36 additions and 22 deletions

View File

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

View File

@ -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

View File

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

View File

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

View File

@ -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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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