Tsukikage7 commented on code in PR #3154:
URL: https://github.com/apache/dubbo-go/pull/3154#discussion_r2692934139
##########
server/server.go:
##########
@@ -176,6 +179,61 @@ func (s *Server) genSvcOpts(handler any, info
*common.ServiceInfo, opts ...Servi
return newSvcOpts, nil
}
+// isNillable checks if a reflect.Value's kind supports nil checking.
+func isNillable(v reflect.Value) bool {
+ switch v.Kind() {
+ case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map,
reflect.Pointer, reflect.Slice:
+ return true
+ default:
+ return false
+ }
+}
+
+// isReflectNil safely checks if a reflect.Value is nil.
+func isReflectNil(v reflect.Value) bool {
+ return isNillable(v) && v.IsNil()
+}
+
+// CallMethodByReflection invokes the given method via reflection and
processes its return values.
+// This is a shared helper function used by both server/server.go and
protocol/triple/server.go.
+func CallMethodByReflection(ctx context.Context, method reflect.Method,
handler any, args []any) (any, error) {
+ in := []reflect.Value{reflect.ValueOf(handler)}
+ in = append(in, reflect.ValueOf(ctx))
+ for _, arg := range args {
+ in = append(in, reflect.ValueOf(arg))
+ }
+ returnValues := method.Func.Call(in)
+
+ // Process return values
+ if len(returnValues) == 1 {
+ if isReflectNil(returnValues[0]) {
+ return nil, nil
+ }
+ if err, ok := returnValues[0].Interface().(error); ok {
+ return nil, err
+ }
+ return nil, nil
+ }
+ var result any
+ var err error
+ if !isReflectNil(returnValues[0]) {
+ result = returnValues[0].Interface()
+ }
+ if len(returnValues) > 1 && !isReflectNil(returnValues[1]) {
+ if e, ok := returnValues[1].Interface().(error); ok {
+ err = e
+ }
+ }
+ return result, err
+}
+
+// createReflectionMethodFunc creates a MethodFunc that calls the given method
via reflection.
+func createReflectionMethodFunc(method reflect.Method) func(ctx
context.Context, args []any, handler any) (any, error) {
+ return func(ctx context.Context, args []any, handler any) (any, error) {
+ return CallMethodByReflection(ctx, method, handler, args)
+ }
+}
+
// Add a method with a name of a different first-letter case
// to achieve interoperability with java
// TODO: The method name case sensitivity in Dubbo-java should be addressed.
Review Comment:
Partially. The enhanceServiceInfo function now registers both GetUser and
getUser style methods, so Go and Java can find each other. But the real fix
should be on dubbo-java side to handle case properly. Kept the TODO as a
reminder - maybe we can push for a fix upstream later.
--
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]