uniugm/admin/apps/mockpro/server/route_desc.go

49 lines
977 B
Go
Raw Normal View History

2025-04-22 15:46:48 +08:00
package server
import (
"admin/apps/mockpro/internal/model/dto"
"admin/lib/web"
)
type PathInfo struct {
Path string `json:"path"`
Method string `json:"method"`
}
type ResourceInfo struct {
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(path string, parentDesc 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{
Desc: parentDesc,
Paths: []*PathInfo{
&PathInfo{
Path: path,
Method: method,
},
},
})
}
})
rsp.List = paths
return nil
}