Alanxtl commented on code in PR #3294:
URL: https://github.com/apache/dubbo-go/pull/3294#discussion_r3090534304
##########
common/rpc_service.go:
##########
@@ -329,6 +330,47 @@ func isExportedOrBuiltinType(t reflect.Type) bool {
return isExported(t.Name()) || t.PkgPath() == ""
}
+// VariadicRPCMethodNames returns exported RPC method names whose final
+// parameter uses Go variadic syntax (...T). The detection reuses suiteMethod
so
+// only methods Dubbo-go would export as RPC methods are included.
+func VariadicRPCMethodNames(svc RPCService) []string {
+ return variadicRPCMethodNames(reflect.TypeOf(svc))
+}
+
+// WarnVariadicRPCMethods emits guidance for exported variadic RPC methods
while
+// keeping existing services compatible.
+func WarnVariadicRPCMethods(serviceName string, svc RPCService) {
+ methodNames := VariadicRPCMethodNames(svc)
+ if len(methodNames) == 0 {
+ return
+ }
+
+ logger.Warnf(
+ "Service %s exports variadic RPC method(s): %s. Existing
services remain supported, but new cross-language or generic contracts should
avoid variadic (...T); prefer []T, request structs, or Triple + Protobuf IDL.",
+ serviceName,
+ strings.Join(methodNames, ", "),
+ )
+}
+
+// variadicRPCMethodNames keeps the result sorted so warnings and tests stay
+// stable regardless of reflection iteration order.
+func variadicRPCMethodNames(typ reflect.Type) []string {
+ if typ == nil {
+ return nil
+ }
+
+ methodNames := make([]string, 0)
+ for i := 0; i < typ.NumMethod(); i++ {
+ method := typ.Method(i)
+ if suiteMethod(method) != nil && method.Type.IsVariadic() {
+ methodNames = append(methodNames, method.Name)
+ }
+ }
+
+ sort.Strings(methodNames)
Review Comment:
这里为啥要sort一下
##########
README_CN.md:
##########
@@ -130,6 +130,12 @@ func main() {
有关使用详情,请参阅 [imports-formatter
README](https://github.com/dubbogo/tools?tab=readme-ov-file#imports-formatter)。
+### variadicrpccheck
+
+一个 warning-only 的扫描工具,用于检测导出的 variadic RPC 契约,并给出跨语言场景下的迁移建议。
Review Comment:
contracts 翻译成 契约 这个合理吗
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]