chore: 并入 iotlcm-admin-svr 历史到 admin-svr/(原提交 49818c6)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// package router
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/agent"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// Agent 系统默认功能的路由,不含业务属性的路由
|
||||
func Agent(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
|
||||
group.Group("/agent", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(
|
||||
service.Middleware().Auth,
|
||||
)
|
||||
group.Bind(
|
||||
agent.NewV1(),
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// package router
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/common"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// Common 通用路由
|
||||
func Common(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
|
||||
group.Group("/common", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(
|
||||
service.Middleware().Auth,
|
||||
)
|
||||
group.Bind(
|
||||
common.NewV1(),
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gmeta"
|
||||
v1 "git.5iot.com/iotlcm-public/iotlcm-admin-svr/api/iot/v1"
|
||||
)
|
||||
|
||||
func TestFullSyncMonitorPermissionDeclarations(t *testing.T) {
|
||||
// A slice of pairs rather than a map: request structs may contain slice
|
||||
// fields (for example the channel scope), which are not hashable.
|
||||
checks := []struct {
|
||||
request any
|
||||
want string
|
||||
}{
|
||||
{v1.FullSyncRunsListReq{}, "cpm:iot:fullSyncRuns:view"},
|
||||
{v1.FullSyncRunDetailReq{}, "cpm:iot:fullSyncRuns:view"},
|
||||
{v1.FullSyncRunFailuresReq{}, "cpm:iot:fullSyncRuns:failures"},
|
||||
{v1.FullSyncRunStartReq{}, "cpm:iot:fullSyncRuns:start"},
|
||||
{v1.FullSyncChannelOptionsReq{}, "cpm:iot:fullSyncRuns:view"},
|
||||
}
|
||||
for _, check := range checks {
|
||||
if got := gmeta.Get(check.request, "x-check-permission").String(); got != check.want {
|
||||
t.Fatalf("%T permission = %q, want %q", check.request, got, check.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gmeta"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/api/iot/v1"
|
||||
)
|
||||
|
||||
func TestFullSyncReplayPermissionDeclarations(t *testing.T) {
|
||||
post := gmeta.Get(v1.FullSyncReplayReq{}, "x-check-permission").String()
|
||||
get := gmeta.Get(v1.FullSyncReplayStatusReq{}, "x-check-permission").String()
|
||||
if post != "cpm:iot:fullSyncRuns:replay" || get != "cpm:iot:fullSyncRuns:replay:view" {
|
||||
t.Fatalf("permission metadata = %q, %q", post, get)
|
||||
}
|
||||
if strings.TrimSpace(post) == "" || strings.TrimSpace(get) == "" {
|
||||
t.Fatal("missing permission")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// package router
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/router/genrouter"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// 生成代码注册
|
||||
func Gen(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
genrouter.Register(ctx, group)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// package router
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/gen_codes"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// GenCodes 代码生成路由
|
||||
func GenCodes(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
group.Group("/genCodes", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(
|
||||
service.Middleware().Auth,
|
||||
)
|
||||
group.Bind(
|
||||
gen_codes.NewV1(),
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// package genrouter
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package genrouter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
var (
|
||||
NoLoginRouter []interface{} // 无需登录
|
||||
LoginRequiredRouter []interface{} // 需要登录
|
||||
)
|
||||
|
||||
// Register 注册通过代码生成的后台路由
|
||||
func Register(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
group.Group("/gen", func(group *ghttp.RouterGroup) {
|
||||
if len(NoLoginRouter) > 0 {
|
||||
group.Bind(NoLoginRouter...)
|
||||
}
|
||||
group.Middleware(service.Middleware().Auth)
|
||||
if len(LoginRequiredRouter) > 0 {
|
||||
group.Bind(LoginRequiredRouter...)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Package genrouter
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
// @AutoGenerate Version
|
||||
package genrouter
|
||||
|
||||
import "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/gen"
|
||||
|
||||
func init() {
|
||||
LoginRequiredRouter = append(LoginRequiredRouter, gen.TestDemo) // 测试单表
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/home"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
func Home(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
group.Group("/home", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(
|
||||
service.Middleware().Auth,
|
||||
)
|
||||
group.Bind(
|
||||
home.NewV1(),
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// package router
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/iot"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// Iot 系统默认功能的路由,不含业务属性的路由
|
||||
func Iot(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
|
||||
group.Group("/iot", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(
|
||||
service.Middleware().Auth,
|
||||
)
|
||||
group.Bind(
|
||||
iot.NewV1(),
|
||||
iot.NewFullSyncReplay(),
|
||||
iot.NewFullSyncMonitor(),
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/api/common/v1"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gmeta"
|
||||
)
|
||||
|
||||
// 右上角未读消息提醒依赖这三个接口,路径、方法或权限码被改动都会导致提醒静默失效。
|
||||
// 权限码必须是 cpc:current:user:没有菜单权限的登录用户也要能获取自己的未读消息。
|
||||
func TestMessageLogUnreadNotificationDeclarations(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
request interface{}
|
||||
path string
|
||||
method string
|
||||
permission string
|
||||
}{
|
||||
{"unreadList", v1.TMessageLogUnreadListReq{}, "/tMessageLog/unreadList", "get", "cpc:current:user"},
|
||||
{"read", v1.TMessageLogReadReq{}, "/tMessageLog/read", "post", "cpc:current:user"},
|
||||
{"readAll", v1.TMessageLogReadAllReq{}, "/tMessageLog/readAll", "post", "cpc:current:user"},
|
||||
}
|
||||
for _, check := range cases {
|
||||
if got := gmeta.Get(check.request, "path").String(); got != check.path {
|
||||
t.Errorf("%s path = %q, want %q", check.name, got, check.path)
|
||||
}
|
||||
if got := gmeta.Get(check.request, "method").String(); got != check.method {
|
||||
t.Errorf("%s method = %q, want %q", check.name, got, check.method)
|
||||
}
|
||||
if got := gmeta.Get(check.request, "x-check-permission").String(); got != check.permission {
|
||||
t.Errorf("%s permission = %q, want %q", check.name, got, check.permission)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// package router
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/monitor"
|
||||
workerdiagnosticcontroller "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/workerdiagnostic"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/rabbitmq"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/websocket"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
workerdiagnosticservice "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service/workerdiagnostic"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/util/gmode"
|
||||
)
|
||||
|
||||
// Monitor 监控功能的路由,不含业务属性的
|
||||
func Monitor(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
group.Group("/monitor", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(
|
||||
service.Middleware().Auth,
|
||||
)
|
||||
group.Bind(
|
||||
monitor.NewV1(),
|
||||
)
|
||||
if workerDiagnosticEnabled(ctx) {
|
||||
group.Bind(
|
||||
workerdiagnosticcontroller.New(workerdiagnosticservice.New(rabbitmq.Publish)),
|
||||
)
|
||||
}
|
||||
group.ALL("/ws", websocket.WsPage)
|
||||
})
|
||||
}
|
||||
|
||||
func workerDiagnosticEnabled(ctx context.Context) bool {
|
||||
return gmode.Mode() != gmode.PRODUCT && g.Cfg().MustGet(ctx, "workerDiagnostic.enabled", false).Bool()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/pay"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
func Pay(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
group.Group("/pay", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(
|
||||
service.Middleware().Auth,
|
||||
)
|
||||
group.Bind(
|
||||
pay.NewV1(),
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
// package router
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
var legacyExportStaticPath = regexp.MustCompile(`(?i)^/(?:app/)?upload/(?:[^/]+/)?user/file/(?:[^/]+/)?export(?:/|$)`)
|
||||
|
||||
// InitRouter 初始化路由
|
||||
func InitRouter(ctx context.Context, s *ghttp.Server) {
|
||||
// Run before static serving as well as API routing; legacy export files must
|
||||
// never bypass download-center authorization through the upload mount.
|
||||
s.BindHookHandler("/*", ghttp.HookBeforeServe, func(r *ghttp.Request) {
|
||||
if legacyExportStaticPath.MatchString(path.Clean(strings.ReplaceAll(r.URL.Path, `\`, "/"))) {
|
||||
r.Response.WriteStatus(http.StatusNotFound)
|
||||
r.ExitAll()
|
||||
}
|
||||
})
|
||||
uploadPath := g.Cfg().MustGet(ctx, "system.upload.local.path").String()
|
||||
if uploadPath != "" {
|
||||
s.AddStaticPath("/upload", resolveUploadStaticPath(uploadPath))
|
||||
}
|
||||
s.Group("/api/v1", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(
|
||||
service.Middleware().Ctx,
|
||||
service.Middleware().ResponseHandler,
|
||||
service.Middleware().CORS,
|
||||
)
|
||||
System(ctx, group)
|
||||
Monitor(ctx, group)
|
||||
Common(ctx, group)
|
||||
GenCodes(ctx, group)
|
||||
Gen(ctx, group)
|
||||
Iot(ctx, group)
|
||||
Agent(ctx, group)
|
||||
Home(ctx, group)
|
||||
Pay(ctx, group)
|
||||
Trade(ctx, group)
|
||||
})
|
||||
//操作日志
|
||||
s.BindHookHandler("/*", ghttp.HookAfterOutput, func(r *ghttp.Request) {
|
||||
service.Middleware().OperationLog(r)
|
||||
})
|
||||
}
|
||||
|
||||
func resolveUploadStaticPath(uploadPath string) string {
|
||||
uploadPath = strings.TrimSpace(uploadPath)
|
||||
if uploadPath == "" {
|
||||
return ""
|
||||
}
|
||||
for _, candidate := range uploadStaticPathCandidates(uploadPath) {
|
||||
if info, err := os.Stat(candidate); err == nil && info.IsDir() {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
return uploadPath
|
||||
}
|
||||
|
||||
func uploadStaticPathCandidates(uploadPath string) []string {
|
||||
var candidates []string
|
||||
for _, root := range []string{
|
||||
os.Getenv("IOTLCM_SERVER_UPLOAD_ROOT"),
|
||||
os.Getenv("IOTLCM_UPLOAD_ROOT"),
|
||||
uploadPath,
|
||||
} {
|
||||
root = strings.TrimSpace(root)
|
||||
if root == "" {
|
||||
continue
|
||||
}
|
||||
candidates = appendUploadStaticPathCandidate(candidates, root)
|
||||
}
|
||||
return candidates
|
||||
}
|
||||
|
||||
func appendUploadStaticPathCandidate(candidates []string, root string) []string {
|
||||
for _, equivalent := range uploadStaticEquivalentPaths(root) {
|
||||
if filepath.IsAbs(equivalent) {
|
||||
candidates = appendUniqueStaticPath(candidates, equivalent)
|
||||
continue
|
||||
}
|
||||
for _, base := range uploadStaticBaseDirs() {
|
||||
candidates = appendUniqueStaticPath(candidates, filepath.Join(base, equivalent))
|
||||
}
|
||||
candidates = appendUniqueStaticPath(candidates, equivalent)
|
||||
}
|
||||
return candidates
|
||||
}
|
||||
|
||||
func uploadStaticEquivalentPaths(root string) []string {
|
||||
root = strings.TrimSpace(root)
|
||||
if root == "" {
|
||||
return nil
|
||||
}
|
||||
paths := []string{root}
|
||||
normalized := filepath.ToSlash(filepath.Clean(root))
|
||||
if normalized == "resource/upload" || strings.HasSuffix(normalized, "/resource/upload") {
|
||||
prefix := strings.TrimSuffix(normalized, "resource/upload")
|
||||
paths = appendUniqueStaticPath(paths, filepath.FromSlash(prefix+"upload"))
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
||||
func uploadStaticBaseDirs() []string {
|
||||
var dirs []string
|
||||
if wd, err := os.Getwd(); err == nil && strings.TrimSpace(wd) != "" {
|
||||
dirs = appendUniqueStaticPath(dirs, wd)
|
||||
}
|
||||
if exe, err := os.Executable(); err == nil && strings.TrimSpace(exe) != "" {
|
||||
dirs = appendUniqueStaticPath(dirs, filepath.Dir(exe))
|
||||
}
|
||||
return dirs
|
||||
}
|
||||
|
||||
func appendUniqueStaticPath(values []string, value string) []string {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return values
|
||||
}
|
||||
cleaned := filepath.Clean(value)
|
||||
for _, existing := range values {
|
||||
if filepath.Clean(strings.TrimSpace(existing)) == cleaned {
|
||||
return values
|
||||
}
|
||||
}
|
||||
return append(values, value)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// package router
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <xxx@example.com>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/system"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// System 系统默认功能的路由,不含业务属性的
|
||||
func System(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
|
||||
group.Group("/system", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(
|
||||
service.Middleware().Auth,
|
||||
)
|
||||
group.Bind(
|
||||
system.NewV1(),
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/controller/trade"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
func Trade(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
group.Group("/trade", func(group *ghttp.RouterGroup) {
|
||||
group.Bind(
|
||||
trade.NewV1(),
|
||||
)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user