feat: standardize REST and RPC routes

This commit is contained in:
2026-08-11 18:55:36 +08:00
parent 53e953c3fc
commit eed82bcf38
8 changed files with 89 additions and 22 deletions

View File

@@ -1,6 +1,8 @@
package routers
import (
"path"
"bsm/full/module/base/mgt/internal/logic/application"
"bsm/full/module/base/mgt/internal/logic/department"
"bsm/full/module/base/mgt/internal/logic/hello"
@@ -14,9 +16,9 @@ import (
"github.com/gin-gonic/gin"
)
// 完成请求地址: ip:port/srvKey/group/xxx
// 完成请求地址: ip:port/rest/srvKey/group/xxx
func Register(srvKey string, engine *gin.Engine) {
base := "/" + srvKey
base := path.Join("/rest", srvKey)
registerAnonymous(base, engine)
registerRouters(base, engine)
}

View File

@@ -0,0 +1,35 @@
package routers
import (
"strings"
"testing"
"github.com/gin-gonic/gin"
)
func TestRoutesUseRESTModulePrefix(t *testing.T) {
gin.SetMode(gin.TestMode)
engine := gin.New()
Register("mgt", engine)
expected := map[string]bool{
"GET /rest/mgt/ping": false,
"POST /rest/mgt/login": false,
"POST /rest/mgt/user/create": false,
"POST /rest/mgt/app/fetch": false,
}
for _, route := range engine.Routes() {
key := route.Method + " " + route.Path
if _, ok := expected[key]; ok {
expected[key] = true
}
if route.Path == "/mgt" || strings.HasPrefix(route.Path, "/mgt/") {
t.Fatalf("legacy route remains registered: %s", route.Path)
}
}
for route, found := range expected {
if !found {
t.Errorf("route not registered: %s", route)
}
}
}