mochengqian commented on code in PR #3294:
URL: https://github.com/apache/dubbo-go/pull/3294#discussion_r3098678950


##########
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



-- 
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]

Reply via email to