-
Notifications
You must be signed in to change notification settings - Fork 121
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
102 changed files
with
860 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Binary file added
BIN
+104 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/concepts/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+103 KB
...urus-plugin-content-docs/current/resource/concepts/basic-microservices-arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+26.3 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/concepts/benchmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+109 KB
.../docusaurus-plugin-content-docs/current/resource/concepts/event-driven-arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+51.8 KB
...cusaurus-plugin-content-docs/current/resource/concepts/layered-arch-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.5 KB
...n/docusaurus-plugin-content-docs/current/resource/concepts/microkernel-arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+149 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/concepts/resilience.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+88 KB
...n/docusaurus-plugin-content-docs/current/resource/concepts/space-based-arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+26.3 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/contributing/clone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+138 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/contributing/compare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+222 KB
.../en/docusaurus-plugin-content-docs/current/resource/contributing/contribute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+314 KB
...en/docusaurus-plugin-content-docs/current/resource/contributing/example_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+137 KB
...n/docusaurus-plugin-content-docs/current/resource/contributing/example_tips.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.5 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/contributing/fork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+156 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/contributing/pr_record.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+92.6 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/example/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+317 KB
...saurus-plugin-content-docs/current/resource/tasks/cli/task-api-demo-postman.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+383 KB
...saurus-plugin-content-docs/current/resource/tasks/cli/task-grpc-demo-grpcui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+247 KB
...aurus-plugin-content-docs/current/resource/tasks/cli/task-grpc-demo-postman.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+314 KB
...s-plugin-content-docs/current/resource/tasks/create/create-from-goland-main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+177 KB
...saurus-plugin-content-docs/current/resource/tasks/create/create-from-goland.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+152 KB
...saurus-plugin-content-docs/current/resource/tasks/create/create-from-vscode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+152 KB
...gin-content-docs/current/resource/tasks/create/create-go-module-from-vscode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+171 KB
...s-plugin-content-docs/current/resource/tasks/create/create-main-from-goland.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+298 KB
...-plugin-content-docs/current/resource/tasks/create/create-main-from-goland2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+275 KB
...-plugin-content-docs/current/resource/tasks/create/create-main-from-goland3.png
Oops, something went wrong.
Binary file added
BIN
+185 KB
...ocusaurus-plugin-content-docs/current/resource/tasks/create/create-new-file.png
Oops, something went wrong.
Binary file added
BIN
+157 KB
...urus-plugin-content-docs/current/resource/tasks/create/open-vscode-terminal.png
Oops, something went wrong.
Binary file added
BIN
+293 KB
...docusaurus-plugin-content-docs/current/resource/tasks/create/run-in-goland1.png
Oops, something went wrong.
Binary file added
BIN
+133 KB
...docusaurus-plugin-content-docs/current/resource/tasks/create/run-in-goland2.png
Oops, something went wrong.
Binary file added
BIN
+425 KB
...docusaurus-plugin-content-docs/current/resource/tasks/create/run-in-goland3.png
Oops, something went wrong.
Binary file added
BIN
+200 KB
.../docusaurus-plugin-content-docs/current/resource/tasks/create/run-in-vscode.png
Oops, something went wrong.
Binary file added
BIN
+100 KB
...rus-plugin-content-docs/current/resource/tasks/create/run-result-in-goland1.png
Oops, something went wrong.
Binary file added
BIN
+99.1 KB
...rus-plugin-content-docs/current/resource/tasks/create/run-result-in-goland2.png
Oops, something went wrong.
Binary file added
BIN
+35.7 KB
...rus-plugin-content-docs/current/resource/tasks/create/run-result-in-goland3.png
Oops, something went wrong.
Binary file added
BIN
+647 KB
...aurus-plugin-content-docs/current/resource/tasks/create/vscode-go-extension.png
Oops, something went wrong.
Binary file added
BIN
+190 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/tasks/dsl/ast-process.png
Oops, something went wrong.
Binary file added
BIN
+323 KB
...plugin-content-docs/current/resource/tasks/installation/goland-plugin-goctl.png
Oops, something went wrong.
Binary file added
BIN
+698 KB
...aurus-plugin-content-docs/current/resource/tasks/installation/goland-plugin.png
Oops, something went wrong.
Binary file added
BIN
+63.1 KB
...saurus-plugin-content-docs/current/resource/tasks/installation/vscode-goctl.png
Oops, something went wrong.
Binary file added
BIN
+75.5 KB
...docusaurus-plugin-content-docs/current/resource/tasks/timer-task/k8scronjob.png
Oops, something went wrong.
Binary file added
BIN
+55.6 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/tutorials/api/signdemo.zip
Binary file not shown.
Binary file added
BIN
+460 KB
.../docusaurus-plugin-content-docs/current/resource/tutorials/cli/github-issue.png
Oops, something went wrong.
Binary file added
BIN
+606 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/tutorials/cli/goctl.png
Oops, something went wrong.
Binary file added
BIN
+245 KB
...n/docusaurus-plugin-content-docs/current/resource/tutorials/cli/goctl_cover.png
Oops, something went wrong.
Binary file added
BIN
+265 KB
i18n/en/docusaurus-plugin-content-docs/current/resource/tutorials/ops/README.png
Oops, something went wrong.
Binary file added
BIN
+372 KB
...ocusaurus-plugin-content-docs/current/resource/tutorials/ops/apicode-docker.png
Oops, something went wrong.
Binary file added
BIN
+67 KB
...cusaurus-plugin-content-docs/current/resource/tutorials/ops/apicode-harbor2.png
Oops, something went wrong.
Binary file added
BIN
+64 KB
...urus-plugin-content-docs/current/resource/tutorials/ops/apicode-harbor2_new.png
Oops, something went wrong.
Binary file added
BIN
+160 KB
...cusaurus-plugin-content-docs/current/resource/tutorials/ops/apicode-harbor3.png
Oops, something went wrong.
Binary file added
BIN
+60.4 KB
...aurus-plugin-content-docs/current/resource/tutorials/ops/apicode-harbor_new.png
Oops, something went wrong.
Binary file added
BIN
+174 KB
...s-plugin-content-docs/current/resource/tutorials/ops/deploy-server-deploy-2.jpg
Oops, something went wrong.
Binary file added
BIN
+201 KB
...rus-plugin-content-docs/current/resource/tutorials/ops/deploy-server-deploy.jpg
Oops, something went wrong.
Binary file added
BIN
+191 KB
...n-content-docs/current/resource/tutorials/ops/deploy-server-jenkins-pipline.jpg
Oops, something went wrong.
Binary file added
BIN
+68.8 KB
...-plugin-content-docs/current/resource/tutorials/ops/deploy-server-pipline-3.png
Oops, something went wrong.
Binary file added
BIN
+169 KB
...-plugin-content-docs/current/resource/tutorials/ops/deploy-server-plpline-2.png
Oops, something went wrong.
Binary file added
BIN
+359 KB
...plugin-content-docs/current/resource/tutorials/ops/gitlab-pz-jenkins-sshkey.jpg
Oops, something went wrong.
Binary file added
BIN
+341 KB
...ocusaurus-plugin-content-docs/current/resource/tutorials/ops/gitlab-ssh-key.png
Oops, something went wrong.
Binary file added
BIN
+158 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209100353045.png
Oops, something went wrong.
Binary file added
BIN
+172 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209100813435.png
Oops, something went wrong.
Binary file added
BIN
+204 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209100852807.png
Oops, something went wrong.
Binary file added
BIN
+360 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209101037256.png
Oops, something went wrong.
Binary file added
BIN
+48.9 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209101148261.png
Oops, something went wrong.
Binary file added
BIN
+422 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209101328400.png
Oops, something went wrong.
Binary file added
BIN
+74.1 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209104638510.png
Oops, something went wrong.
Binary file added
BIN
+281 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209104946101.png
Oops, something went wrong.
Binary file added
BIN
+360 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209105921610.png
Oops, something went wrong.
Binary file added
BIN
+331 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209110010562.png
Oops, something went wrong.
Binary file added
BIN
+105 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209111135979.png
Oops, something went wrong.
Binary file added
BIN
+79.6 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209111325922.png
Oops, something went wrong.
Binary file added
BIN
+380 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209111450217.png
Oops, something went wrong.
Binary file added
BIN
+110 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209111612564.png
Oops, something went wrong.
Binary file added
BIN
+281 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209112430241.png
Oops, something went wrong.
Binary file added
BIN
+300 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209112756140.png
Oops, something went wrong.
Binary file added
BIN
+74.1 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209134737504.png
Oops, something went wrong.
Binary file added
BIN
+390 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209175734040.png
Oops, something went wrong.
Binary file added
BIN
+62.6 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209190928092.png
Oops, something went wrong.
Binary file added
BIN
+43 KB
...gin-content-docs/current/resource/tutorials/ops/image-20220209190928092_new.png
Oops, something went wrong.
Binary file added
BIN
+148 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209191633736.png
Oops, something went wrong.
Binary file added
BIN
+391 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209191757422.png
Oops, something went wrong.
Binary file added
BIN
+291 KB
...-content-docs/current/resource/tutorials/ops/image-20220209191757422_newnew.png
Oops, something went wrong.
Binary file added
BIN
+87.4 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209195140145.png
Oops, something went wrong.
Binary file added
BIN
+352 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209195418130.png
Oops, something went wrong.
Binary file added
BIN
+175 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209195724082.png
Oops, something went wrong.
Binary file added
BIN
+101 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209195853856.png
Oops, something went wrong.
Binary file added
BIN
+399 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209200922797.png
Oops, something went wrong.
Binary file added
BIN
+185 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209201022699.png
Oops, something went wrong.
Binary file added
BIN
+150 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209201812134.png
Oops, something went wrong.
Binary file added
BIN
+171 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220209201927466.png
Oops, something went wrong.
Binary file added
BIN
+224 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220210095715913.png
Oops, something went wrong.
Binary file added
BIN
+133 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220211142524599.png
Oops, something went wrong.
Binary file added
BIN
+197 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220211142613065.png
Oops, something went wrong.
Binary file added
BIN
+758 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220211142729231.png
Oops, something went wrong.
Binary file added
BIN
+146 KB
...-plugin-content-docs/current/resource/tutorials/ops/image-20220213134628497.png
Oops, something went wrong.
Binary file added
BIN
+91.6 KB
.../docusaurus-plugin-content-docs/current/resource/tutorials/ops/jenkins-user.png
Oops, something went wrong.
115 changes: 115 additions & 0 deletions
115
i18n/en/docusaurus-plugin-content-docs/current/tasks/cli/api-demo.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,115 @@ | ||
--- | ||
title: api demo code generation | ||
slug: /docs/tasks/cli/api-demo | ||
--- | ||
|
||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
## Overview | ||
|
||
After completing the <a href="/docs/tasks/installation/goctl" target="_blank">goctl installation</a>, we can create a minimal HTTP service to get an overview of goctl's go-zero api service. | ||
|
||
## Task Targets | ||
|
||
1. Learn how to create a minimized HTTP service using goctl | ||
1. Preliminary understanding of the project structure of go-zero | ||
|
||
|
||
## Preparing | ||
|
||
1. <a href="/docs/tasks" target="_blank">Complete golang installation</a> | ||
1. <a href="/docs/tasks/installation/goctl" target="_blank">Complete goctl installation</a> | ||
|
||
## Code Generation | ||
|
||
```shell | ||
# Create workspaces and enter the directory | ||
$ mkdir -p ~/workspace/api && cd ~/workspace/api | ||
# Execute instructions generated demo service | ||
$ goctl api new demo | ||
Done. | ||
``` | ||
After executing the instruction, a demo directory will be generated under the current directory that contains a minimized HTTP service and we will check the directory structure of the service. | ||
|
||
```shell | ||
$ cd ~/workspace/api/demo | ||
$ ls | ||
demo.api demo.go etc go.mod internal | ||
$ tree | ||
. | ||
├── demo.api | ||
├── demo.go | ||
├── etc | ||
│ └── demo-api.yaml | ||
├── go.mod | ||
└── internal | ||
├── config | ||
│ └── config.go | ||
├── handler | ||
│ ├── demohandler.go | ||
│ └── routes.go | ||
├── logic | ||
│ └── demologic.go | ||
├── svc | ||
│ └── servicecontext.go | ||
└── types | ||
└── types.go | ||
``` | ||
|
||
:::note | ||
API, RPC, Job Directory structure is similar to what the go-zero project structure can look at <a href="/docs/concepts/layout">Project Structure</a> | ||
::: | ||
|
||
## Write simple logic code | ||
|
||
After completing the above code generation, we can find `~/workspace/api/demo/internal/logic/demologic.go` files, add c odes between line `27` and `28` : | ||
|
||
```go | ||
resp = new(types.Response) | ||
resp.Message = req.Name | ||
``` | ||
|
||
## Start service | ||
|
||
After writing the above code, we can start the service with the following instructions: | ||
|
||
```shell | ||
# Enter service directory | ||
$ cd ~/workspace/api/demo | ||
# to organize dependencies | ||
$ go mod tidy | ||
# Run go program | ||
$ go run demo.go | ||
``` | ||
|
||
When you see the following output `Starting server at 0.0.0.0.0:888...`indicates that the service has been successfully started, then we come to visit the HTTP service. | ||
|
||
<Tabs> | ||
<TabItem value="terminal" label="终端中访问" default> | ||
|
||
```bash | ||
$ curl --request GET 'http://127.0.0.0.1:8888/from/me' | ||
`````` | ||
|
||
When you see the output in the terminal `{"message":"me"}` on behalf of your service successfully started. | ||
|
||
</TabItem> | ||
|
||
<TabItem value="postman" label="Postman 中访问" default> | ||
|
||
![postman](../../resource/tasks/cli/task-api-demo-postman.png) | ||
|
||
<center> Access in Postman </center> | ||
|
||
The service on your behalf has been successfully launched when you see the following output in Postman. | ||
|
||
```json | ||
{ | ||
"message": "me" | ||
} | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
|
||
When you come here following the steps in the document, congratulations, you have completed the creation and startup of the simplest go-zero api service. For instructions on using the `goctl` tool, please refer to <a href ="/docs/tutorials/cli/overview" target="_blank">"CLI Tools"</a>, for a complete description of the go-zero api service, please refer to <a href ="/docs/tutorials/http/server/configuration/service" target="_blank">《HTTP Server》</a>. |
103 changes: 103 additions & 0 deletions
103
i18n/en/docusaurus-plugin-content-docs/current/tasks/cli/api-format.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,103 @@ | ||
--- | ||
title: api file format | ||
slug: /docs/tasks/cli/api-format | ||
--- | ||
|
||
## Overview | ||
|
||
After the api file is written, the content of our api is uneven, as follows | ||
|
||
```go | ||
syntax= "v1" | ||
|
||
info( | ||
key1:value1 | ||
key2:value2 | ||
longkey:longvalue | ||
) | ||
|
||
type Foo { | ||
Bar string | ||
Baz int | ||
} | ||
``` | ||
|
||
This api file is not read. We can use `goctl api format` to format api files. | ||
|
||
## Task Targets | ||
|
||
1. familiar with the use of goctl api format | ||
1. Learn about the function of the goctl api format command | ||
|
||
## Preparing | ||
|
||
1. <a href="/docs/tasks/installation/goctl" target="_blank">Complete goctl installation</a> | ||
|
||
## Format api file | ||
|
||
1. Create an api file and copy the following content to the `demo.api` file | ||
|
||
```go | ||
syntax = "v1" | ||
|
||
type User { | ||
Id int64 `json:"id"` | ||
Name string `json:"name"` | ||
Age int `json:"age"` | ||
Description string `json:"description"` | ||
} | ||
|
||
type Student { | ||
Id int64 `json:"id"` | ||
No int64 `json:"no"` | ||
Name string `json:"name"` | ||
Age int `json:"age"` | ||
Description string `json:"description"` | ||
} | ||
|
||
service User { | ||
@handler ping | ||
get /ping | ||
} | ||
``` | ||
|
||
1. Create workspace and directory | ||
|
||
```bash | ||
$ mkdir -p ~/workspace/api/format | ||
``` | ||
|
||
1. Copy the above `demo.api` files to `~/workspace/api/format under directory` | ||
|
||
1. Format api file | ||
|
||
```bash | ||
$ cd ~/workspace/api/format | ||
$ goctl api format --dir demo.api | ||
``` | ||
|
||
1. View formatted api files | ||
|
||
```bash | ||
syntax = "v1" | ||
type User { | ||
Id int64 `json:"id"` | ||
Name string `json:"name"` | ||
Age int `json:"age"` | ||
Description string `json:"description"` | ||
} | ||
type Student { | ||
Id int64 `json:"id"` | ||
No int64 `json:"no"` | ||
Name string `json:"name"` | ||
Age int `json:"age"` | ||
Description string `json:"description"` | ||
} | ||
service User { | ||
@handler ping | ||
get /ping | ||
} | ||
``` |
172 changes: 172 additions & 0 deletions
172
i18n/en/docusaurus-plugin-content-docs/current/tasks/cli/grpc-demo.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,172 @@ | ||
--- | ||
title: gRPC demo code generation | ||
slug: /docs/tasks/cli/grpc-demo | ||
--- | ||
|
||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
## Overview | ||
|
||
After completing the <a href="/docs/tasks/installation/goctl" target="_blank">goctl installation</a>, we can create a minimal gRPC service to get an overview of goctl's go-zero gRPC service. | ||
|
||
## Task Targets | ||
|
||
1. Learn how to create a minimized gRPC service using goctl | ||
1. Preliminary understanding of the project structure of go-zero | ||
1. Preliminary method of gRPC local debugging | ||
|
||
|
||
## Preparing | ||
|
||
1. <a href="/docs/tasks" target="_blank">Complete golang installation</a> | ||
1. <a href="/docs/tasks/installation/goctl" target="_blank">Complete goctl installation</a> | ||
|
||
## Code Generation | ||
|
||
```shell | ||
# Create workspaces and enter the directory | ||
$ mkdir -p ~/workspace/rpc && cd ~/workspace/rpc | ||
# Execute instructions generated demo service | ||
$ goctl rpc new demo | ||
Done. | ||
``` | ||
After executing the instruction, a demo directory will be generated under the current directory that contains a minimized gRPC service. We will check the directory structure of the service. | ||
|
||
```shell | ||
# Enter the demo service directory | ||
$ cd ~/workspace/rpc/demo | ||
# view file list | ||
$ ls | ||
demo demo.go demo.proto democlient etc go.mod internal | ||
# View directory interface | ||
$ tree | ||
. | ||
├── demo | ||
│ ├── demo.pb.go | ||
│ └── demo_grpc.pb.go | ||
├── demo.go | ||
├── demo.proto | ||
├── democlient | ||
│ └── demo.go | ||
├── etc | ||
│ └── demo.yaml | ||
├── go.mod | ||
└── internal | ||
├── config | ||
│ └── config.go | ||
├── logic | ||
│ └── pinglogic.go | ||
├── server | ||
│ └── demoserver.go | ||
└── svc | ||
└── servicecontext.go | ||
``` | ||
|
||
:::note | ||
API, RPC, Job Directory structure is similar to what the go-zero project structure can look at <a href="/docs/concepts/layout">Project Structure</a> | ||
::: | ||
|
||
## Write simple logic code | ||
|
||
After completing the above code generation, we can find `~/workspace/api/demo/internal/logic/demologic.go` files, replace codes at line `29` as follows : | ||
|
||
```go | ||
return &demo.Response{ | ||
Pong:"pong", | ||
}, nil | ||
``` | ||
|
||
Then set your profile `~/workspace/rpc/depo/etc/demo.yaml`remove `3` to `7 to` lines of content, then add-on `Mode: dev` to end, making configuration file content: | ||
|
||
```yaml | ||
Name: demo.rpc | ||
ListenOn: 0.0.0.0:8080 | ||
Mode: dev | ||
|
||
``` | ||
:::Note | ||
goctl generates minimized gRPC service by registering information about the current service from ETCD Register, so registration is not required for this demonstration, so the registration center configuration in the configuration file has been deleted. | ||
::: | ||
## Start service | ||
After writing the above code, we can start the service with the following instructions: | ||
```shell | ||
# Enter service directory | ||
$ cd ~/workspace/rpc/demo | ||
# Organize dependencies | ||
$ go mod tidy | ||
# Run go program | ||
$ go go run demo.go | ||
``` | ||
|
||
When you see the following output `Starting rpc server at 0.0.0.0:8080...`indicates that the service has been successfully started, then we come to visit the gRPC service. | ||
|
||
<Tabs> | ||
<TabItem value="grpcurl" label="grpcurl 访问" default> | ||
|
||
```bash | ||
$ grpcurl -plaintext 127.0.0.1:8080 demo.Demo/Ping | ||
`` | ||
|
||
on behalf of your service has been successfully launched when you see the following output in the terminal. | ||
|
||
```json | ||
{ | ||
"pong": "pong" | ||
} | ||
``` | ||
|
||
:::note NOTE | ||
grpcurl is a command-line tool for accessing gRPC services, for details, please refer to <a href="https://github.com/fullstorydev/grpcurl">《grpcurl》</a> | ||
::: | ||
|
||
</TabItem> | ||
|
||
<TabItem value="grpcui" label="grpcui 访问" default> | ||
|
||
Start the grpcui service at the terminal: | ||
|
||
```bash | ||
$ grpcui -plaintext 127.0.0.1:8080 | ||
```` | ||
then visit the `Ping` interface in the browser. The service on behalf of you has started successfully when you see the following output. | ||
```json | ||
{ | ||
"pong": "pong" | ||
} | ||
``` | ||
|
||
![postman](../../resource/tasks/cli/task-grpc-demo-grpcui.png) | ||
|
||
<center> Access in grpcui </center> | ||
|
||
:::note | ||
grpcui is a gRPC UI debugging tool to access gRPC services. See <a href="https://github.com/fullstorydev/grpcui">Grpcui</a> | ||
::: | ||
|
||
</TabItem> | ||
|
||
<TabItem value="postman" label="Postman 中访问" default> | ||
|
||
![postman](../../resource/tasks/cli/task-grpc-demo-postman.png) | ||
|
||
<center> Access in Postman </center> | ||
|
||
The service on your behalf has been successfully launched when you see the following output in Postman. | ||
|
||
```json | ||
{ | ||
"message": "me" | ||
} | ||
``` | ||
</TabItem> | ||
|
||
</Tabs> | ||
|
||
When you come here following the steps in the document, congratulations, you have completed the creation and startup of the simplest go-zero api service. For instructions on using the `goctl` tool, please refer to <a href ="/docs/tutorials/cli/overview" target="_blank">"CLI Tools"</a>, for a complete description of the go-zero api service, please refer to <a href ="/docs/tutorials/http/server/configuration/service" target="_blank">《HTTP Server》</a>. |
Oops, something went wrong.