This is an automated email from the ASF dual-hosted git repository.
xuetaoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-website.git
The following commit(s) were added to refs/heads/master by this push:
new 602e7681761 docs(golang-sdk): add InvokeWithType usage for generic
invocation (#3186)
602e7681761 is described below
commit 602e768176163ac20931869227073ca85ca407d8
Author: CAICAII <[email protected]>
AuthorDate: Thu Jan 22 13:59:30 2026 +0800
docs(golang-sdk): add InvokeWithType usage for generic invocation (#3186)
---
.../overview/mannual/golang-sdk/refer/generic.md | 32 ++++++++++++++++++++++
.../overview/mannual/golang-sdk/refer/generic.md | 32 ++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/content/en/overview/mannual/golang-sdk/refer/generic.md
b/content/en/overview/mannual/golang-sdk/refer/generic.md
index 99baaa7f267..b20ff5cd778 100644
--- a/content/en/overview/mannual/golang-sdk/refer/generic.md
+++ b/content/en/overview/mannual/golang-sdk/refer/generic.md
@@ -159,5 +159,37 @@ The Invoke method of GenericService takes four parameters:
Note: In the current version, parameterless calls may cause crashing issues.
+### Automatic Deserialization with InvokeWithType
+
+In the `Invoke` method, the return value `resp` is a `map` type (for
`MapGeneralizer`), requiring users to manually perform type conversion. To
simplify this process, dubbo-go provides the `InvokeWithType` method, which can
automatically deserialize the result into a user-specified struct.
+
+```go
+// Define the result struct
+type User struct {
+ ID string
+ Name string
+ Age int32
+}
+
+var user User
+// Deserialize the result directly into the user struct
+err := refConf.
+ GetRPCService().(*generic.GenericService).
+ InvokeWithType(
+ context.TODO(),
+ "GetUser",
+ []string{"java.lang.String"},
+ []hessian.Object{"A003"},
+ &user,
+ )
+
+if err != nil {
+ // Handle error
+}
+fmt.Println(user.Name)
+```
+
+Note: `InvokeWithType` currently only supports the default Map generic
invocation.
+
Related reading: [【Dubbo-go Service Proxy
Model】](https://blog.csdn.net/weixin_39860915/article/details/122738548)
diff --git a/content/zh-cn/overview/mannual/golang-sdk/refer/generic.md
b/content/zh-cn/overview/mannual/golang-sdk/refer/generic.md
index 7a1217db900..337f3dd3e59 100644
--- a/content/zh-cn/overview/mannual/golang-sdk/refer/generic.md
+++ b/content/zh-cn/overview/mannual/golang-sdk/refer/generic.md
@@ -159,4 +159,36 @@ GenericService 的 Invoke 方法接收四个参数,分别是:
注意:在目前版本中,无参调用会出现崩溃问题。
+### 泛化调用获取结果自动反序列化
+
+在 `Invoke` 方法中,返回值 `resp` 是一个 `map` 类型(对于
`MapGeneralizer`),用户需要手动进行类型转换。为了简化这一过程,dubbo-go 提供了 `InvokeWithType`
方法,可以将结果自动反序列化为用户指定的结构体。
+
+```go
+// 定义结果结构体
+type User struct {
+ ID string
+ Name string
+ Age int32
+}
+
+var user User
+// 直接将结果反序列化到 user 结构体中
+err := refConf.
+ GetRPCService().(*generic.GenericService).
+ InvokeWithType(
+ context.TODO(),
+ "GetUser",
+ []string{"java.lang.String"},
+ []hessian.Object{"A003"},
+ &user,
+ )
+
+if err != nil {
+ // 处理错误
+}
+fmt.Println(user.Name)
+```
+
+注意:`InvokeWithType` 目前仅支持默认的 Map 泛化方式。
+
相关阅读:[【Dubbo-go
服务代理模型】](https://blog.csdn.net/weixin_39860915/article/details/122738548)