You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/hertz/getting-started/_index.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,18 @@ For more information on how to use hz, please refer to: [hz](https://www.cloudwe
111
111
### Generate/Complete the Sample Code
112
112
113
113
1. Create the hertz_demo folder in the current directory and go to that directory.
114
-
2. Generate code `hz new`. If your codes are not placed under `GOPATH`, you need to refer [here](https://www.cloudwego.io/docs/hertz/tutorials/toolkit/usage/) and add `-module` (or `-mod`) flag to name your custom module.
114
+
2. Generating code
115
+
- Use `hz new` directly, if not currently in `GOPATH`, you need to add `-module` or `-mod` flag to specify a custom module name. See [here](https://www.cloudwego.io/docs/hertz/tutorials/toolkit/usage/) for details.
116
+
- Code generation by specifying an already defined idl file, e.g. `hz new -idl hello.thrift`.
117
+
```thrift
118
+
namespace go hello.world
119
+
120
+
service HelloService {
121
+
string Hello(1: string name);
122
+
}
123
+
```
124
+
After execution, a scaffolding of the Hertz project is created in the current directory, with a `ping` interface for testing.
125
+
115
126
3. Tidy & get dependencies.
116
127
117
128
```bash
@@ -148,6 +159,25 @@ If nothing goes wrong, we can see the following output:
148
159
149
160
You have now successfully launched Hertz Server successfully and completed an API call.
150
161
162
+
### Updating project code
163
+
164
+
If you need to make further updates to the project, you should use the `hz update` command, here is an example of adding a `Bye` method.
165
+
166
+
```thrift
167
+
namespace go hello.world
168
+
169
+
service HelloService {
170
+
string Hello(1: string name);
171
+
string Bye(1: string name);
172
+
}
173
+
```
174
+
175
+
At this point, run `hz update` from the project root directory to update the project.
- If the dependency of the IDL is not in the same path as the main IDL, you need to add the `-I` option, which means the path to search for the IDL, equivalent to the `-I` command of protoc.
260
+
- When writing update command, you need to specify not only the IDL file that defines `service`, but also all the dependency files, because protobuf's dependency files will not be updated automatically.
258
261
259
-
3. As you can see
262
+
3. As you can see
260
263
261
-
Add new method under "biz/handler/hello/hello_service.go";
262
-
The file "new_service.go" and the corresponding "Method3" method have been added under "biz/handler/hello".
264
+
Add new method under `biz/handler/hello/hello_service.go`;
265
+
The file `new_service.go` and the corresponding "Method3" method have been added under `biz/handler/hello`.
263
266
264
-
Now let's develop the "Method2" interface:
267
+
Now let's develop the "Method2" interface:
265
268
266
-
```go
267
-
// Method2 .
268
-
// @router /other [POST]
269
-
funcMethod2(ctxcontext.Context, c *app.RequestContext) {
270
-
varerrerror
271
-
varreq hello.OtherReq
272
-
err = c.BindAndValidate(&req)
273
-
if err != nil {
274
-
c.String(400, err.Error())
275
-
return
276
-
}
269
+
```go
270
+
// Method2 .
271
+
// @router /other [POST]
272
+
funcMethod2(ctxcontext.Context, c *app.RequestContext) {
1. When writing the update command, you only need to specify the IDL file that defines the `service`. hz will automatically generate all the dependencies for that file.
163
+
161
164
3. As you can see
162
165
163
-
Add new method under "biz/handler/hello/example/hello_service.go"<br>
164
-
The file "new_service.go" and the corresponding "NewMethod" method have been added under "biz/handler/hello/example"
166
+
Add new method under `biz/handler/hello/example/hello_service.go`<br>
167
+
The file `new_service.go` and the corresponding "NewMethod" method have been added under `biz/handler/hello/example`.
0 commit comments