uniugm/admin/apps/mockpro/server/route_desc.go
2025-04-24 20:39:31 +08:00

52 lines
1.1 KiB
Go

package server
import (
"admin/apps/mockpro/internal/model/dto"
"admin/lib/web"
"path/filepath"
)
type PathInfo struct {
Path string `json:"path"`
Method string `json:"method"`
}
type ResourceInfo struct {
Path string `json:"path"`
Desc string `json:"desc"`
Paths []*PathInfo `json:"paths"`
}
type CmdListRsp struct {
List []*ResourceInfo `json:"list"`
}
func (srv *Server) commandlist(ctx *WebContext, req *dto.NilReq, rsp *CmdListRsp) error {
paths := make([]*ResourceInfo, 0)
srv.engine.TravelPaths(func(parentPath, parentDesc string, path string, method string, handlers ...web.HandlerFunc) {
find := false
for _, v := range paths {
if v.Desc == parentDesc {
v.Paths = append(v.Paths, &PathInfo{
Path: path,
Method: method,
})
find = true
break
}
}
if !find {
paths = append(paths, &ResourceInfo{
Path: filepath.Base(parentPath),
Desc: parentDesc,
Paths: []*PathInfo{
&PathInfo{
Path: path,
Method: method,
},
},
})
}
})
rsp.List = paths
return nil
}