Skip to content

Commit c7ca974

Browse files
committed
Update README files.
1 parent dd42e4c commit c7ca974

File tree

2 files changed

+189
-0
lines changed

2 files changed

+189
-0
lines changed

cmd/dubbogo-cli-v2/README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,98 @@ methods: []
4646
This command will generate a dubbo-go example, you can refer to the example [HOWTO](https://github.com/apache/dubbo-go-samples/blob/master/HOWTO.md) to run.
4747

4848
![img.png](docs/demo/img.png)
49+
50+
51+
### Add hessian2 registry statement
52+
#### main.go
53+
```go
54+
package main
55+
56+
//go:generate go run "github.com/dubbogo/tools/cmd/dubbogo-cli-v2" hessian --include pkg
57+
func main() {
58+
59+
}
60+
```
61+
#### pkg/demo.go
62+
63+
```go
64+
package pkg
65+
66+
type Demo0 struct {
67+
A string `json:"a"`
68+
B string `json:"b"`
69+
}
70+
71+
func (*Demo0) JavaClassName() string {
72+
return "org.apache.dubbo.Demo0"
73+
}
74+
75+
type Demo1 struct {
76+
C string `json:"c"`
77+
}
78+
79+
func (*Demo1) JavaClassName() string {
80+
return "org.apache.dubbo.Demo1"
81+
}
82+
83+
```
84+
85+
#### Execute `go generate`
86+
87+
```shell
88+
go generate
89+
```
90+
91+
#### Console logs
92+
```shell
93+
2022/01/28 11:58:11 === Generate start [pkg\demo.go] ===
94+
2022/01/28 11:58:11 === Registry POJO [pkg\demo.go].Demo0 ===
95+
2022/01/28 11:58:11 === Registry POJO [pkg\demo.go].Demo1 ===
96+
2022/01/28 11:58:11 === Generate completed [pkg\demo.go] ===
97+
```
98+
99+
#### Result
100+
101+
pkg/demo.go
102+
103+
```go
104+
package pkg
105+
106+
import (
107+
"github.com/apache/dubbo-go-hessian2"
108+
)
109+
110+
type Demo0 struct {
111+
A string `json:"a"`
112+
B string `json:"b"`
113+
}
114+
115+
func (*Demo0) JavaClassName() string {
116+
return "org.apache.dubbo.Demo0"
117+
}
118+
119+
type Demo1 struct {
120+
C string `json:"c"`
121+
}
122+
123+
func (*Demo1) JavaClassName() string {
124+
return "org.apache.dubbo.Demo1"
125+
}
126+
127+
func init() {
128+
129+
hessian.RegisterPOJO(&Demo0{})
130+
131+
hessian.RegisterPOJO(&Demo1{})
132+
133+
}
134+
135+
```
136+
137+
#### Command flags
138+
139+
| flag | description | default |
140+
|:-------:|:---------------------------------------:|:--------------:|
141+
| include | Preprocess files parent directory path. | ./ |
142+
| thread | Worker thread limit. | (cpu core) * 2 |
143+
| error | Only print error message. | false |

cmd/dubbogo-cli-v2/README_CN.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,97 @@ methods: []
4646
该命令会生成一个 dubbo-go 的样例,该样例可以参考 [HOWTO](https://github.com/apache/dubbo-go-samples/blob/master/HOWTO.md) 运行:
4747

4848
![img.png](docs/demo/img.png)
49+
50+
### 快速添加 hessian2 注册方法
51+
#### main.go
52+
```go
53+
package main
54+
55+
//go:generate go run "github.com/dubbogo/tools/cmd/dubbogo-cli-v2" hessian --include pkg
56+
func main() {
57+
58+
}
59+
```
60+
#### pkg/demo.go
61+
62+
```go
63+
package pkg
64+
65+
type Demo0 struct {
66+
A string `json:"a"`
67+
B string `json:"b"`
68+
}
69+
70+
func (*Demo0) JavaClassName() string {
71+
return "org.apache.dubbo.Demo0"
72+
}
73+
74+
type Demo1 struct {
75+
C string `json:"c"`
76+
}
77+
78+
func (*Demo1) JavaClassName() string {
79+
return "org.apache.dubbo.Demo1"
80+
}
81+
82+
```
83+
84+
#### 执行 `go generate`
85+
86+
```shell
87+
go generate
88+
```
89+
90+
#### 日志
91+
```shell
92+
2022/01/28 11:58:11 === Generate start [pkg\demo.go] ===
93+
2022/01/28 11:58:11 === Registry POJO [pkg\demo.go].Demo0 ===
94+
2022/01/28 11:58:11 === Registry POJO [pkg\demo.go].Demo1 ===
95+
2022/01/28 11:58:11 === Generate completed [pkg\demo.go] ===
96+
```
97+
98+
#### 结果
99+
100+
pkg/demo.go
101+
102+
```go
103+
package pkg
104+
105+
import (
106+
"github.com/apache/dubbo-go-hessian2"
107+
)
108+
109+
type Demo0 struct {
110+
A string `json:"a"`
111+
B string `json:"b"`
112+
}
113+
114+
func (*Demo0) JavaClassName() string {
115+
return "org.apache.dubbo.Demo0"
116+
}
117+
118+
type Demo1 struct {
119+
C string `json:"c"`
120+
}
121+
122+
func (*Demo1) JavaClassName() string {
123+
return "org.apache.dubbo.Demo1"
124+
}
125+
126+
func init() {
127+
128+
hessian.RegisterPOJO(&Demo0{})
129+
130+
hessian.RegisterPOJO(&Demo1{})
131+
132+
}
133+
134+
```
135+
136+
#### 命令行参数
137+
138+
| flag | description | default |
139+
|:-------:|:---------------------------------------:|:--------------:|
140+
| include | Preprocess files parent directory path. | ./ |
141+
| thread | Worker thread limit. | (cpu core) * 2 |
142+
| error | Only print error message. | false |

0 commit comments

Comments
 (0)