Bladeren bron

refactor(http):重构路径生成器函数命名

- 将 pathGenerator 函数重命名为 PathGenerator
- 更新路由配置中对路径生成器的调用
- 保持默认路径生成逻辑不变
- 确保服务名称和方法名称正确传递
- 维持路径生成器函数的可定制性
- 验证路径生成结果符合预期格式
lihf 9 uur geleden
bovenliggende
commit
9aa57accde
2 gewijzigde bestanden met toevoegingen van 5 en 5 verwijderingen
  1. 4 4
      transport/http/handler/path.go
  2. 1 1
      transport/http/handler/route.go

+ 4 - 4
transport/http/handler/path.go

@@ -6,14 +6,14 @@ type PathGeneratorFunc func(serviceName, methodName string) string
 
 var pathGeneratorFunc PathGeneratorFunc = defaultPathGenerator
 
-func pathGenerator(serviceName, methodName string) string {
-	return pathGeneratorFunc(serviceName, methodName)
-}
-
 func defaultPathGenerator(serviceName, methodName string) string {
 	return fmt.Sprintf("/api/%s/%s", serviceName, methodName)
 }
 
+func PathGenerator(serviceName, methodName string) string {
+	return pathGeneratorFunc(serviceName, methodName)
+}
+
 func SetPathGeneratorFunc(f PathGeneratorFunc) {
 	if f == nil {
 		panic("pathGeneratorFunc is nil")

+ 1 - 1
transport/http/handler/route.go

@@ -114,7 +114,7 @@ func GetOptionByServiceDescriptor(sd *desc.ServiceDescriptor, serviceName, metho
 		}
 	}
 	if option.Path == "" {
-		option.Path = pathGenerator(serviceName, methodName)
+		option.Path = PathGenerator(serviceName, methodName)
 	}
 	if option.Method == "" {
 		option.Method = http2.MethodPost