CAICAIIs opened a new pull request, #3174:
URL: https://github.com/apache/dubbo-go/pull/3174
### Summary
- Add `InvokeWithType` method to `GenericService` for automatic
deserialization of generic call results
- Move `GenericService` from `config/generic` to `filter/generic`
- Enhance `OnResponse` in `genericFilter` to support auto deserialization
### Motivation
1. Add InvokeWithType
Previously, generic call returns `map[string]any`, users have to manually
convert it to struct:
```
// Before
result, _ := genericService.Invoke(ctx, "getUser", []string{"String"},
[]any{"123"})
m := result.(map[string]any)
user := &User{
Name: m["name"].(string),
Age: int(m["age"].(float64)),
}
```
Now with InvokeWithType, it's much simpler:
```
// After
var user User
err := genericService.InvokeWithType(ctx, "getUser",
[]string{"java.lang.String"}, []hessian.Object{"123"}, &user)
fmt.Println(user.Name, user.Age)
```
2. Move GenericService from config/generic to filter/generic
GenericService is a service definition for generic invocation, not a
configuration. Placing it under config/ was inappropriate because:
1. GenericService is an RPC service struct, not a configuration item
2. It was separated from the generic invocation logic in filter/generic/
(filter, generalizer), which increased cognitive overhead
3. The config/ directory should only contain configuration-related code
Now all generic invocation related code is consolidated in filter/generic/.
### Description
Fixes #3172
Related to #3167
### Checklist
- [x] I confirm the target branch is `develop`
- [x] Code has passed local testing
- [x] I have added tests that prove my fix is effective or that my feature
works
--
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]