-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
738 additions
and
1,792 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
content/zh-cn/overview/mannual/golang-sdk/refer/nacos.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
--- | ||
aliases: | ||
- /zh/docs3-v2/golang-sdk/tutorial/develop/registry/nacos/ | ||
- /zh-cn/docs3-v2/golang-sdk/tutorial/develop/registry/nacos/ | ||
description: 使用 Nacos 作为注册中心 | ||
title: 使用 Nacos 作为注册中心 | ||
type: docs | ||
weight: 10 | ||
--- | ||
|
||
|
||
|
||
## 1. 准备工作 | ||
|
||
- dubbo-go cli 工具和依赖工具已安装 | ||
- 创建一个新的 demo 应用 | ||
|
||
## 2. 使用 grpc_cli 工具进行 Dubbo 服务调试 | ||
|
||
### 2.1 开启服务端 | ||
示例:user.go: | ||
```go | ||
func (u *UserProvider) GetUser(ctx context.Context, userStruct *CallUserStruct) (*User, error) { | ||
fmt.Printf("=======================\nreq:%#v\n", userStruct) | ||
rsp := User{"A002", "Alex Stocks", 18, userStruct.SubInfo} | ||
fmt.Printf("=======================\nrsp:%#v\n", rsp) | ||
return &rsp, nil | ||
} | ||
|
||
``` | ||
服务端开启一个服务,名为GetUser,传入一个CallUserStruct的参数,返回一个User参数\ | ||
CallUserStruct参数定义: | ||
```go | ||
type CallUserStruct struct { | ||
ID string | ||
Male bool | ||
SubInfo SubInfo // 嵌套子结构 | ||
} | ||
func (cs CallUserStruct) JavaClassName() string { | ||
return "com.ikurento.user.CallUserStruct" | ||
} | ||
|
||
type SubInfo struct { | ||
SubID string | ||
SubMale bool | ||
SubAge int | ||
} | ||
|
||
func (s SubInfo) JavaClassName() string { | ||
return "com.ikurento.user.SubInfo" | ||
} | ||
|
||
``` | ||
User结构定义: | ||
```go | ||
type User struct { | ||
Id string | ||
Name string | ||
Age int32 | ||
SubInfo SubInfo // 嵌套上述子结构SubInfo | ||
} | ||
|
||
func (u *User) JavaClassName() string { | ||
return "com.ikurento.user.User" | ||
} | ||
``` | ||
|
||
开启服务: | ||
|
||
`cd server `\ | ||
`source builddev.sh`\ | ||
`go run .` | ||
|
||
### 2.2 定义请求体(打解包协议) | ||
|
||
请求体定义为json文件,约定键值均为string\ | ||
键对应go语言struct字段名例如"ID"、"Name" ,值对应"type@val"\ | ||
其中type支持string int bool time,val使用string 来初始化,如果只填写type则初始化为零值。 | ||
约定每个struct必须有JavaClassName字段,务必与server端严格对应 | ||
|
||
见userCall.json: | ||
```json | ||
{ | ||
"ID": "string@A000", | ||
"Male": "bool@true", | ||
"SubInfo": { | ||
"SubID": "string@A001", | ||
"SubMale": "bool@false", | ||
"SubAge": "int@18", | ||
"JavaClassName":"[email protected]" | ||
}, | ||
"JavaClassName": "[email protected]" | ||
} | ||
``` | ||
userCall.json将参数CallUserStruct的结构及子结构SubInfo都定义了出来,并且给请求参数赋值。 | ||
|
||
user.json 同理,作为返回值不需要赋初始值,但JavaClassName字段一定与server端严格对应 | ||
```go | ||
{ | ||
"ID": "string", | ||
"Name": "string", | ||
"Age": "int", | ||
"JavaClassName": "[email protected]", | ||
"SubInfo": { | ||
"SubID": "string", | ||
"SubMale": "bool", | ||
"SubAge": "int", | ||
"JavaClassName":"[email protected]" | ||
} | ||
} | ||
``` | ||
|
||
### 2.3 执行请求 | ||
`dubbogo-cli call --h=localhost --p 20001 --proto=dubbo --i=com.ikurento.user.UserProvider --method=GetUser --sendObj="./userCall.json" --recvObj="./user.json"` | ||
|
||
cli端打印结果: | ||
```log | ||
2020/10/26 20:47:45 Created pkg: | ||
2020/10/26 20:47:45 &{ID:A000 Male:true SubInfo:0xc00006ea20 JavaClassName:com.ikurento.user.CallUserStruct} | ||
2020/10/26 20:47:45 SubInfo: | ||
2020/10/26 20:47:45 &{SubID:A001 SubMale:false SubAge:18 JavaClassName:com.ikurento.user.SubInfo} | ||
2020/10/26 20:47:45 Created pkg: | ||
2020/10/26 20:47:45 &{ID: Name: Age:0 JavaClassName:com.ikurento.user.User SubInfo:0xc00006ec90} | ||
2020/10/26 20:47:45 SubInfo: | ||
2020/10/26 20:47:45 &{SubID: SubMale:false SubAge:0 JavaClassName:com.ikurento.user.SubInfo} | ||
2020/10/26 20:47:45 connected to localhost:20001! | ||
2020/10/26 20:47:45 try calling interface:com.ikurento.user.UserProvider.GetUser | ||
2020/10/26 20:47:45 with protocol:dubbo | ||
2020/10/26 20:47:45 After 3ms , Got Rsp: | ||
2020/10/26 20:47:45 &{ID:A002 Name:Alex Stocks Age:18 JavaClassName: SubInfo:0xc0001241b0} | ||
2020/10/26 20:47:45 SubInfo: | ||
2020/10/26 20:47:45 &{SubID:A001 SubMale:false SubAge:18 JavaClassName:}``` | ||
``` | ||
可看到详细的请求体赋值情况,以及返回结果和耗时。支持嵌套结构 | ||
|
||
server端打印结果 | ||
``` | ||
======================= | ||
req:&main.CallUserStruct{ID:"A000", Male:true, SubInfo:main.SubInfo{SubID:"A001", SubMale:false, SubAge:18}} | ||
======================= | ||
``` | ||
可见接收到了来自cli的数据 |
9 changes: 0 additions & 9 deletions
9
content/zh-cn/overview/mannual/golang-sdk/tutorial/healthcheck/_index.md
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
content/zh-cn/overview/mannual/golang-sdk/tutorial/healthcheck/kubernetes.md
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
content/zh-cn/overview/mannual/golang-sdk/tutorial/healthcheck/start-check.md
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.