├── .github └── workflows │ └── push-grpc-server-example-image.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── go.mod ├── go.sum ├── main.go ├── proto.pb ├── proto ├── echo.pb.go ├── echo.proto ├── echo_grpc.pb.go ├── helloworld.pb.go ├── helloworld.proto ├── helloworld_grpc.pb.go ├── import.pb.go ├── import.proto ├── src.pb.go ├── src.proto └── src_grpc.pb.go └── t └── cert ├── apisix.crt └── apisix.key /.github/workflows/push-grpc-server-example-image.yml: -------------------------------------------------------------------------------- 1 | name: Build and Push image 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'release/*' 7 | 8 | jobs: 9 | publish_image: 10 | name: Build and Push grpc-server-example image 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Check out code 14 | uses: actions/checkout@v2.3.5 15 | 16 | - name: Extract Tags name 17 | if: ${{ startsWith(github.ref, 'refs/tags/') }} 18 | id: tag_env 19 | shell: bash 20 | run: | 21 | echo "##[set-output name=version;]$(echo ${GITHUB_REF##*/})" 22 | 23 | - name: Set up QEMU 24 | uses: docker/setup-qemu-action@v1 25 | 26 | - name: Set up Docker Buildx 27 | uses: docker/setup-buildx-action@v1 28 | 29 | - name: Login to DockerHub 30 | uses: docker/login-action@v1 31 | with: 32 | username: ${{ secrets.DOCKERHUB_USERNAME }} 33 | password: ${{ secrets.DOCKERHUB_TOKEN }} 34 | 35 | - name: Build and push Docker image 36 | uses: docker/build-push-action@v2 37 | with: 38 | context: . 39 | push: true 40 | platforms: linux/amd64,linux/arm64 41 | tags: api7/grpc-server-example:${{ steps.tag_env.outputs.version }} 42 | build-args: | 43 | VERSION=${{ steps.tag_env.outputs.version }} 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Ignore binary 15 | /grpc_server_example 16 | 17 | grpc_server_example-amd64.tar.gz 18 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.14.10 AS build-env 2 | 3 | RUN rm -rf /etc/localtime \ 4 | && ln -s /usr/share/zoneinfo/Hongkong /etc/localtime \ 5 | && dpkg-reconfigure -f noninteractive tzdata 6 | 7 | WORKDIR /build 8 | COPY . . 9 | RUN GOPROXY=https://goproxy.cn,direct go build -o grpc_server_example main.go 10 | 11 | FROM centos:centos7 12 | 13 | WORKDIR /grpc_server_example 14 | COPY --from=build-env /build/grpc_server_example bin/ 15 | COPY --from=build-env /build/t t/ 16 | 17 | WORKDIR /grpc_server_example/bin 18 | EXPOSE 50051 19 | EXPOSE 50052 20 | ENTRYPOINT ["/grpc_server_example/bin/grpc_server_example"] 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: package 2 | package: 3 | CGO_ENABLED=0 go build 4 | tar -czvf grpc_server_example-amd64.tar.gz grpc_server_example 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #### Dependencies 2 | golang v1.11+ 3 | 4 | # run 5 | 6 | ```shell 7 | cd path_to_grpc_server_example 8 | 9 | go run main.go 10 | ``` 11 | 12 | # run in docker 13 | 14 | ```shell 15 | docker build -t grpc_server_example:latest . 16 | docker run grpc_server_example:latest 17 | ``` 18 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/api7/grpc_server_example 2 | 3 | go 1.11 4 | 5 | require ( 6 | github.com/golang/protobuf v1.5.0 7 | google.golang.org/grpc v1.32.0 8 | google.golang.org/protobuf v1.27.1 // indirect 9 | ) 10 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 4 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 5 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= 6 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 7 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 8 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 9 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 10 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 11 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 12 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 13 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 14 | github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= 15 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 16 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 17 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 18 | github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= 19 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 20 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 21 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 22 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 23 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 24 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 25 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 26 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 27 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 28 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 29 | golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= 30 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 31 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 32 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 33 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 34 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 35 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 36 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= 37 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 38 | golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 39 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 40 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 41 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 42 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 43 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 44 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 45 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 46 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 47 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 48 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 49 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= 50 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 51 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 52 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 53 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 54 | google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0= 55 | google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= 56 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 57 | google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= 58 | google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 59 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 60 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 61 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | //go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/helloworld.proto 20 | //go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/import.proto 21 | //go:generate protoc --include_imports --descriptor_set_out=proto.pb --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/src.proto 22 | //go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/echo.proto 23 | 24 | // Package main implements a server for Greeter service. 25 | package main 26 | 27 | import ( 28 | "context" 29 | "crypto/tls" 30 | "crypto/x509" 31 | "flag" 32 | "fmt" 33 | "io" 34 | "io/ioutil" 35 | "log" 36 | "net" 37 | "os" 38 | "os/signal" 39 | "syscall" 40 | "time" 41 | 42 | "google.golang.org/grpc" 43 | "google.golang.org/grpc/codes" 44 | "google.golang.org/grpc/credentials" 45 | "google.golang.org/grpc/reflection" 46 | "google.golang.org/grpc/status" 47 | 48 | pb "github.com/api7/grpc_server_example/proto" 49 | ) 50 | 51 | var ( 52 | grpcAddr = ":50051" 53 | grpcsAddr = ":50052" 54 | grpcsMtlsAddr string 55 | 56 | crtFilePath = "../t/cert/apisix.crt" 57 | keyFilePath = "../t/cert/apisix.key" 58 | caFilePath string 59 | ) 60 | 61 | func init() { 62 | flag.StringVar(&grpcAddr, "grpc-address", grpcAddr, "address for grpc") 63 | flag.StringVar(&grpcsAddr, "grpcs-address", grpcsAddr, "address for grpcs") 64 | flag.StringVar(&grpcsMtlsAddr, "grpcs-mtls-address", grpcsMtlsAddr, "address for grpcs in mTLS") 65 | flag.StringVar(&crtFilePath, "crt", crtFilePath, "path to certificate") 66 | flag.StringVar(&keyFilePath, "key", keyFilePath, "path to key") 67 | flag.StringVar(&caFilePath, "ca", caFilePath, "path to ca") 68 | } 69 | 70 | // server is used to implement helloworld.GreeterServer. 71 | type server struct { 72 | // Embed the unimplemented server 73 | pb.UnimplementedGreeterServer 74 | pb.UnimplementedTestImportServer 75 | pb.UnimplementedEchoServiceServer 76 | } 77 | 78 | // SayHello implements helloworld.GreeterServer 79 | func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { 80 | log.Printf("Received: %v", in.Name) 81 | log.Printf("Enum Gender: %v", in.GetGender()) 82 | msg := "Hello " + in.Name 83 | 84 | person := in.GetPerson() 85 | if person != nil { 86 | if person.GetName() != "" { 87 | msg += fmt.Sprintf(", name: %v", person.GetName()) 88 | } 89 | if person.GetAge() != 0 { 90 | msg += fmt.Sprintf(", age: %v", person.GetAge()) 91 | } 92 | } 93 | 94 | return &pb.HelloReply{ 95 | Message: msg, 96 | Items: in.GetItems(), 97 | Gender: in.GetGender(), 98 | }, nil 99 | } 100 | 101 | // GetErrResp implements helloworld.GreeterServer 102 | func (s *server) GetErrResp(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { 103 | st := status.New(codes.Unavailable, "Out of service") 104 | st, err := st.WithDetails(&pb.ErrorDetail{ 105 | Code: 1, 106 | Message: "The server is out of service", 107 | Type: "service", 108 | }) 109 | 110 | if err != nil { 111 | panic(fmt.Sprintf("Unexpected error attaching metadata: %v", err)) 112 | } 113 | 114 | return nil, st.Err() 115 | } 116 | 117 | func (s *server) SayHelloAfterDelay(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { 118 | 119 | select { 120 | case <-time.After(1 * time.Second): 121 | fmt.Println("overslept") 122 | case <-ctx.Done(): 123 | errStr := ctx.Err().Error() 124 | if ctx.Err() == context.DeadlineExceeded { 125 | return nil, status.Error(codes.DeadlineExceeded, errStr) 126 | } 127 | } 128 | 129 | time.Sleep(1 * time.Second) 130 | 131 | log.Printf("Received: %v", in.Name) 132 | 133 | return &pb.HelloReply{Message: "Hello delay " + in.Name}, nil 134 | } 135 | 136 | func (s *server) Plus(ctx context.Context, in *pb.PlusRequest) (*pb.PlusReply, error) { 137 | log.Printf("Received: %v %v", in.A, in.B) 138 | return &pb.PlusReply{Result: in.A + in.B}, nil 139 | } 140 | 141 | // SayHelloServerStream streams HelloReply back to the client. 142 | func (s *server) SayHelloServerStream(req *pb.HelloRequest, stream pb.Greeter_SayHelloServerStreamServer) error { 143 | log.Printf("Received server side stream req: %v\n", req) 144 | 145 | // Say Hello 5 times. 146 | for i := 0; i < 5; i++ { 147 | if err := stream.Send(&pb.HelloReply{ 148 | Message: fmt.Sprintf("Hello %s", req.Name), 149 | }); err != nil { 150 | return status.Errorf(codes.Unavailable, "Unable to stream request back to client: %v", err) 151 | } 152 | } 153 | return nil 154 | } 155 | 156 | // SayHelloClientStream receives a stream of HelloRequest from a client. 157 | func (s *server) SayHelloClientStream(stream pb.Greeter_SayHelloClientStreamServer) error { 158 | log.Println("SayHello client side streaming has been initiated.") 159 | cache := "" 160 | for { 161 | req, err := stream.Recv() 162 | if err == io.EOF { 163 | return stream.SendAndClose(&pb.HelloReply{Message: cache}) 164 | } 165 | if err != nil { 166 | return status.Errorf(codes.Unavailable, "Failed to read client stream: %v", err) 167 | } 168 | cache = fmt.Sprintf("%sHello %s!", cache, req.Name) 169 | } 170 | } 171 | 172 | // SayHelloBidirectionalStream establishes a bidirectional stream with the client. 173 | func (s *server) SayHelloBidirectionalStream(stream pb.Greeter_SayHelloBidirectionalStreamServer) error { 174 | log.Println("SayHello bidirectional streaming has been initiated.") 175 | 176 | for { 177 | req, err := stream.Recv() 178 | if err == io.EOF { 179 | return stream.Send(&pb.HelloReply{Message: "stream ended"}) 180 | } 181 | if err != nil { 182 | return status.Errorf(codes.Unavailable, "Failed to read client stream: %v", err) 183 | } 184 | 185 | // A small 0.5 sec sleep 186 | time.Sleep(500 * time.Millisecond) 187 | 188 | if err := stream.Send(&pb.HelloReply{Message: fmt.Sprintf("Hello %s", req.Name)}); err != nil { 189 | return status.Errorf(codes.Unknown, "Failed to stream response back to client: %v", err) 190 | } 191 | } 192 | } 193 | 194 | // Echo implements echo.EchoService/Echo 195 | func (s *server) Echo(ctx context.Context, in *pb.EchoMsg) (*pb.EchoMsg, error) { 196 | msg := in.Msg 197 | return &pb.EchoMsg{ 198 | Msg: msg, 199 | }, nil 200 | } 201 | 202 | func (s *server) Run(ctx context.Context, in *pb.Request) (*pb.Response, error) { 203 | return &pb.Response{Body: in.User.Name + " " + in.Body}, nil 204 | } 205 | 206 | func main() { 207 | flag.Parse() 208 | 209 | go func() { 210 | lis, err := net.Listen("tcp", grpcAddr) 211 | if err != nil { 212 | log.Fatalf("failed to listen: %v", err) 213 | } 214 | s := grpc.NewServer() 215 | reflection.Register(s) 216 | pb.RegisterGreeterServer(s, &server{}) 217 | pb.RegisterTestImportServer(s, &server{}) 218 | pb.RegisterEchoServiceServer(s, &server{}) 219 | if err := s.Serve(lis); err != nil { 220 | log.Fatalf("failed to serve: %v", err) 221 | } 222 | }() 223 | 224 | go func() { 225 | lis, err := net.Listen("tcp", grpcsAddr) 226 | if err != nil { 227 | log.Fatalf("failed to listen: %v", err) 228 | } 229 | 230 | c, err := credentials.NewServerTLSFromFile(crtFilePath, keyFilePath) 231 | if err != nil { 232 | log.Fatalf("credentials.NewServerTLSFromFile err: %v", err) 233 | } 234 | s := grpc.NewServer(grpc.Creds(c)) 235 | reflection.Register(s) 236 | pb.RegisterGreeterServer(s, &server{}) 237 | pb.RegisterEchoServiceServer(s, &server{}) 238 | if err := s.Serve(lis); err != nil { 239 | log.Fatalf("failed to serve: %v", err) 240 | } 241 | }() 242 | 243 | if grpcsMtlsAddr != "" { 244 | go func() { 245 | lis, err := net.Listen("tcp", grpcsMtlsAddr) 246 | if err != nil { 247 | log.Fatalf("failed to listen: %v", err) 248 | } 249 | 250 | certificate, err := tls.LoadX509KeyPair(crtFilePath, keyFilePath) 251 | if err != nil { 252 | log.Fatalf("could not load server key pair: %s", err) 253 | } 254 | 255 | certPool := x509.NewCertPool() 256 | ca, err := ioutil.ReadFile(caFilePath) 257 | if err != nil { 258 | log.Fatalf("could not read ca certificate: %s", err) 259 | } 260 | 261 | if ok := certPool.AppendCertsFromPEM(ca); !ok { 262 | log.Fatalf("failed to append client certs") 263 | } 264 | 265 | c := credentials.NewTLS(&tls.Config{ 266 | ClientAuth: tls.RequireAndVerifyClientCert, 267 | Certificates: []tls.Certificate{certificate}, 268 | ClientCAs: certPool, 269 | }) 270 | s := grpc.NewServer(grpc.Creds(c)) 271 | reflection.Register(s) 272 | pb.RegisterGreeterServer(s, &server{}) 273 | if err := s.Serve(lis); err != nil { 274 | log.Fatalf("failed to serve: %v", err) 275 | } 276 | }() 277 | } 278 | 279 | signals := make(chan os.Signal) 280 | signal.Notify(signals, os.Interrupt, syscall.SIGTERM) 281 | sig := <-signals 282 | log.Printf("get signal %s, exit\n", sig.String()) 283 | } 284 | -------------------------------------------------------------------------------- /proto.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/api7/grpc_server_example/c37c9aaecb69b2332592f5db5f16612779489e25/proto.pb -------------------------------------------------------------------------------- /proto/echo.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.27.1 4 | // protoc v3.19.4 5 | // source: proto/echo.proto 6 | 7 | package proto 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type EchoMsg struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Msg string `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` 29 | } 30 | 31 | func (x *EchoMsg) Reset() { 32 | *x = EchoMsg{} 33 | if protoimpl.UnsafeEnabled { 34 | mi := &file_proto_echo_proto_msgTypes[0] 35 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 36 | ms.StoreMessageInfo(mi) 37 | } 38 | } 39 | 40 | func (x *EchoMsg) String() string { 41 | return protoimpl.X.MessageStringOf(x) 42 | } 43 | 44 | func (*EchoMsg) ProtoMessage() {} 45 | 46 | func (x *EchoMsg) ProtoReflect() protoreflect.Message { 47 | mi := &file_proto_echo_proto_msgTypes[0] 48 | if protoimpl.UnsafeEnabled && x != nil { 49 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 50 | if ms.LoadMessageInfo() == nil { 51 | ms.StoreMessageInfo(mi) 52 | } 53 | return ms 54 | } 55 | return mi.MessageOf(x) 56 | } 57 | 58 | // Deprecated: Use EchoMsg.ProtoReflect.Descriptor instead. 59 | func (*EchoMsg) Descriptor() ([]byte, []int) { 60 | return file_proto_echo_proto_rawDescGZIP(), []int{0} 61 | } 62 | 63 | func (x *EchoMsg) GetMsg() string { 64 | if x != nil { 65 | return x.Msg 66 | } 67 | return "" 68 | } 69 | 70 | var File_proto_echo_proto protoreflect.FileDescriptor 71 | 72 | var file_proto_echo_proto_rawDesc = []byte{ 73 | 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 74 | 0x74, 0x6f, 0x12, 0x04, 0x65, 0x63, 0x68, 0x6f, 0x22, 0x1b, 0x0a, 0x07, 0x45, 0x63, 0x68, 0x6f, 75 | 0x4d, 0x73, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 76 | 0x52, 0x03, 0x6d, 0x73, 0x67, 0x32, 0x33, 0x0a, 0x0b, 0x45, 0x63, 0x68, 0x6f, 0x53, 0x65, 0x72, 77 | 0x76, 0x69, 0x63, 0x65, 0x12, 0x24, 0x0a, 0x04, 0x45, 0x63, 0x68, 0x6f, 0x12, 0x0d, 0x2e, 0x65, 78 | 0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x1a, 0x0d, 0x2e, 0x65, 0x63, 79 | 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 80 | 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 81 | } 82 | 83 | var ( 84 | file_proto_echo_proto_rawDescOnce sync.Once 85 | file_proto_echo_proto_rawDescData = file_proto_echo_proto_rawDesc 86 | ) 87 | 88 | func file_proto_echo_proto_rawDescGZIP() []byte { 89 | file_proto_echo_proto_rawDescOnce.Do(func() { 90 | file_proto_echo_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_echo_proto_rawDescData) 91 | }) 92 | return file_proto_echo_proto_rawDescData 93 | } 94 | 95 | var file_proto_echo_proto_msgTypes = make([]protoimpl.MessageInfo, 1) 96 | var file_proto_echo_proto_goTypes = []interface{}{ 97 | (*EchoMsg)(nil), // 0: echo.EchoMsg 98 | } 99 | var file_proto_echo_proto_depIdxs = []int32{ 100 | 0, // 0: echo.EchoService.Echo:input_type -> echo.EchoMsg 101 | 0, // 1: echo.EchoService.Echo:output_type -> echo.EchoMsg 102 | 1, // [1:2] is the sub-list for method output_type 103 | 0, // [0:1] is the sub-list for method input_type 104 | 0, // [0:0] is the sub-list for extension type_name 105 | 0, // [0:0] is the sub-list for extension extendee 106 | 0, // [0:0] is the sub-list for field type_name 107 | } 108 | 109 | func init() { file_proto_echo_proto_init() } 110 | func file_proto_echo_proto_init() { 111 | if File_proto_echo_proto != nil { 112 | return 113 | } 114 | if !protoimpl.UnsafeEnabled { 115 | file_proto_echo_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 116 | switch v := v.(*EchoMsg); i { 117 | case 0: 118 | return &v.state 119 | case 1: 120 | return &v.sizeCache 121 | case 2: 122 | return &v.unknownFields 123 | default: 124 | return nil 125 | } 126 | } 127 | } 128 | type x struct{} 129 | out := protoimpl.TypeBuilder{ 130 | File: protoimpl.DescBuilder{ 131 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 132 | RawDescriptor: file_proto_echo_proto_rawDesc, 133 | NumEnums: 0, 134 | NumMessages: 1, 135 | NumExtensions: 0, 136 | NumServices: 1, 137 | }, 138 | GoTypes: file_proto_echo_proto_goTypes, 139 | DependencyIndexes: file_proto_echo_proto_depIdxs, 140 | MessageInfos: file_proto_echo_proto_msgTypes, 141 | }.Build() 142 | File_proto_echo_proto = out.File 143 | file_proto_echo_proto_rawDesc = nil 144 | file_proto_echo_proto_goTypes = nil 145 | file_proto_echo_proto_depIdxs = nil 146 | } 147 | -------------------------------------------------------------------------------- /proto/echo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package echo; 4 | option go_package="./proto"; 5 | 6 | service EchoService { 7 | rpc Echo (EchoMsg) returns (EchoMsg); 8 | } 9 | 10 | message EchoMsg { 11 | string msg = 1; 12 | } 13 | -------------------------------------------------------------------------------- /proto/echo_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-grpc v1.2.0 4 | // - protoc v3.19.4 5 | // source: proto/echo.proto 6 | 7 | package proto 8 | 9 | import ( 10 | context "context" 11 | grpc "google.golang.org/grpc" 12 | codes "google.golang.org/grpc/codes" 13 | status "google.golang.org/grpc/status" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the grpc package it is being compiled against. 18 | // Requires gRPC-Go v1.32.0 or later. 19 | const _ = grpc.SupportPackageIsVersion7 20 | 21 | // EchoServiceClient is the client API for EchoService service. 22 | // 23 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 24 | type EchoServiceClient interface { 25 | Echo(ctx context.Context, in *EchoMsg, opts ...grpc.CallOption) (*EchoMsg, error) 26 | } 27 | 28 | type echoServiceClient struct { 29 | cc grpc.ClientConnInterface 30 | } 31 | 32 | func NewEchoServiceClient(cc grpc.ClientConnInterface) EchoServiceClient { 33 | return &echoServiceClient{cc} 34 | } 35 | 36 | func (c *echoServiceClient) Echo(ctx context.Context, in *EchoMsg, opts ...grpc.CallOption) (*EchoMsg, error) { 37 | out := new(EchoMsg) 38 | err := c.cc.Invoke(ctx, "/echo.EchoService/Echo", in, out, opts...) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return out, nil 43 | } 44 | 45 | // EchoServiceServer is the server API for EchoService service. 46 | // All implementations must embed UnimplementedEchoServiceServer 47 | // for forward compatibility 48 | type EchoServiceServer interface { 49 | Echo(context.Context, *EchoMsg) (*EchoMsg, error) 50 | mustEmbedUnimplementedEchoServiceServer() 51 | } 52 | 53 | // UnimplementedEchoServiceServer must be embedded to have forward compatible implementations. 54 | type UnimplementedEchoServiceServer struct { 55 | } 56 | 57 | func (UnimplementedEchoServiceServer) Echo(context.Context, *EchoMsg) (*EchoMsg, error) { 58 | return nil, status.Errorf(codes.Unimplemented, "method Echo not implemented") 59 | } 60 | func (UnimplementedEchoServiceServer) mustEmbedUnimplementedEchoServiceServer() {} 61 | 62 | // UnsafeEchoServiceServer may be embedded to opt out of forward compatibility for this service. 63 | // Use of this interface is not recommended, as added methods to EchoServiceServer will 64 | // result in compilation errors. 65 | type UnsafeEchoServiceServer interface { 66 | mustEmbedUnimplementedEchoServiceServer() 67 | } 68 | 69 | func RegisterEchoServiceServer(s grpc.ServiceRegistrar, srv EchoServiceServer) { 70 | s.RegisterService(&EchoService_ServiceDesc, srv) 71 | } 72 | 73 | func _EchoService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 74 | in := new(EchoMsg) 75 | if err := dec(in); err != nil { 76 | return nil, err 77 | } 78 | if interceptor == nil { 79 | return srv.(EchoServiceServer).Echo(ctx, in) 80 | } 81 | info := &grpc.UnaryServerInfo{ 82 | Server: srv, 83 | FullMethod: "/echo.EchoService/Echo", 84 | } 85 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 86 | return srv.(EchoServiceServer).Echo(ctx, req.(*EchoMsg)) 87 | } 88 | return interceptor(ctx, in, info, handler) 89 | } 90 | 91 | // EchoService_ServiceDesc is the grpc.ServiceDesc for EchoService service. 92 | // It's only intended for direct use with grpc.RegisterService, 93 | // and not to be introspected or modified (even as a copy) 94 | var EchoService_ServiceDesc = grpc.ServiceDesc{ 95 | ServiceName: "echo.EchoService", 96 | HandlerType: (*EchoServiceServer)(nil), 97 | Methods: []grpc.MethodDesc{ 98 | { 99 | MethodName: "Echo", 100 | Handler: _EchoService_Echo_Handler, 101 | }, 102 | }, 103 | Streams: []grpc.StreamDesc{}, 104 | Metadata: "proto/echo.proto", 105 | } 106 | -------------------------------------------------------------------------------- /proto/helloworld.pb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Code generated by protoc-gen-go. DO NOT EDIT. 16 | // versions: 17 | // protoc-gen-go v1.30.0 18 | // protoc v3.21.12 19 | // source: proto/helloworld.proto 20 | 21 | package proto 22 | 23 | import ( 24 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 25 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 26 | reflect "reflect" 27 | sync "sync" 28 | ) 29 | 30 | const ( 31 | // Verify that this generated code is sufficiently up-to-date. 32 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 33 | // Verify that runtime/protoimpl is sufficiently up-to-date. 34 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 35 | ) 36 | 37 | type Gender int32 38 | 39 | const ( 40 | Gender_GENDER_UNKNOWN Gender = 0 41 | Gender_GENDER_MALE Gender = 1 42 | Gender_GENDER_FEMALE Gender = 2 43 | ) 44 | 45 | // Enum value maps for Gender. 46 | var ( 47 | Gender_name = map[int32]string{ 48 | 0: "GENDER_UNKNOWN", 49 | 1: "GENDER_MALE", 50 | 2: "GENDER_FEMALE", 51 | } 52 | Gender_value = map[string]int32{ 53 | "GENDER_UNKNOWN": 0, 54 | "GENDER_MALE": 1, 55 | "GENDER_FEMALE": 2, 56 | } 57 | ) 58 | 59 | func (x Gender) Enum() *Gender { 60 | p := new(Gender) 61 | *p = x 62 | return p 63 | } 64 | 65 | func (x Gender) String() string { 66 | return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) 67 | } 68 | 69 | func (Gender) Descriptor() protoreflect.EnumDescriptor { 70 | return file_proto_helloworld_proto_enumTypes[0].Descriptor() 71 | } 72 | 73 | func (Gender) Type() protoreflect.EnumType { 74 | return &file_proto_helloworld_proto_enumTypes[0] 75 | } 76 | 77 | func (x Gender) Number() protoreflect.EnumNumber { 78 | return protoreflect.EnumNumber(x) 79 | } 80 | 81 | // Deprecated: Use Gender.Descriptor instead. 82 | func (Gender) EnumDescriptor() ([]byte, []int) { 83 | return file_proto_helloworld_proto_rawDescGZIP(), []int{0} 84 | } 85 | 86 | type Person struct { 87 | state protoimpl.MessageState 88 | sizeCache protoimpl.SizeCache 89 | unknownFields protoimpl.UnknownFields 90 | 91 | Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` 92 | Age int32 `protobuf:"varint,2,opt,name=age,proto3" json:"age,omitempty"` 93 | } 94 | 95 | func (x *Person) Reset() { 96 | *x = Person{} 97 | if protoimpl.UnsafeEnabled { 98 | mi := &file_proto_helloworld_proto_msgTypes[0] 99 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 100 | ms.StoreMessageInfo(mi) 101 | } 102 | } 103 | 104 | func (x *Person) String() string { 105 | return protoimpl.X.MessageStringOf(x) 106 | } 107 | 108 | func (*Person) ProtoMessage() {} 109 | 110 | func (x *Person) ProtoReflect() protoreflect.Message { 111 | mi := &file_proto_helloworld_proto_msgTypes[0] 112 | if protoimpl.UnsafeEnabled && x != nil { 113 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 114 | if ms.LoadMessageInfo() == nil { 115 | ms.StoreMessageInfo(mi) 116 | } 117 | return ms 118 | } 119 | return mi.MessageOf(x) 120 | } 121 | 122 | // Deprecated: Use Person.ProtoReflect.Descriptor instead. 123 | func (*Person) Descriptor() ([]byte, []int) { 124 | return file_proto_helloworld_proto_rawDescGZIP(), []int{0} 125 | } 126 | 127 | func (x *Person) GetName() string { 128 | if x != nil { 129 | return x.Name 130 | } 131 | return "" 132 | } 133 | 134 | func (x *Person) GetAge() int32 { 135 | if x != nil { 136 | return x.Age 137 | } 138 | return 0 139 | } 140 | 141 | type HelloRequest struct { 142 | state protoimpl.MessageState 143 | sizeCache protoimpl.SizeCache 144 | unknownFields protoimpl.UnknownFields 145 | 146 | Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` 147 | Items []string `protobuf:"bytes,2,rep,name=items,proto3" json:"items,omitempty"` 148 | Gender Gender `protobuf:"varint,3,opt,name=gender,proto3,enum=helloworld.Gender" json:"gender,omitempty"` 149 | Person *Person `protobuf:"bytes,4,opt,name=person,proto3" json:"person,omitempty"` 150 | } 151 | 152 | func (x *HelloRequest) Reset() { 153 | *x = HelloRequest{} 154 | if protoimpl.UnsafeEnabled { 155 | mi := &file_proto_helloworld_proto_msgTypes[1] 156 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 157 | ms.StoreMessageInfo(mi) 158 | } 159 | } 160 | 161 | func (x *HelloRequest) String() string { 162 | return protoimpl.X.MessageStringOf(x) 163 | } 164 | 165 | func (*HelloRequest) ProtoMessage() {} 166 | 167 | func (x *HelloRequest) ProtoReflect() protoreflect.Message { 168 | mi := &file_proto_helloworld_proto_msgTypes[1] 169 | if protoimpl.UnsafeEnabled && x != nil { 170 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 171 | if ms.LoadMessageInfo() == nil { 172 | ms.StoreMessageInfo(mi) 173 | } 174 | return ms 175 | } 176 | return mi.MessageOf(x) 177 | } 178 | 179 | // Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. 180 | func (*HelloRequest) Descriptor() ([]byte, []int) { 181 | return file_proto_helloworld_proto_rawDescGZIP(), []int{1} 182 | } 183 | 184 | func (x *HelloRequest) GetName() string { 185 | if x != nil { 186 | return x.Name 187 | } 188 | return "" 189 | } 190 | 191 | func (x *HelloRequest) GetItems() []string { 192 | if x != nil { 193 | return x.Items 194 | } 195 | return nil 196 | } 197 | 198 | func (x *HelloRequest) GetGender() Gender { 199 | if x != nil { 200 | return x.Gender 201 | } 202 | return Gender_GENDER_UNKNOWN 203 | } 204 | 205 | func (x *HelloRequest) GetPerson() *Person { 206 | if x != nil { 207 | return x.Person 208 | } 209 | return nil 210 | } 211 | 212 | type HelloReply struct { 213 | state protoimpl.MessageState 214 | sizeCache protoimpl.SizeCache 215 | unknownFields protoimpl.UnknownFields 216 | 217 | Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` 218 | Items []string `protobuf:"bytes,2,rep,name=items,proto3" json:"items,omitempty"` 219 | Gender Gender `protobuf:"varint,3,opt,name=gender,proto3,enum=helloworld.Gender" json:"gender,omitempty"` 220 | } 221 | 222 | func (x *HelloReply) Reset() { 223 | *x = HelloReply{} 224 | if protoimpl.UnsafeEnabled { 225 | mi := &file_proto_helloworld_proto_msgTypes[2] 226 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 227 | ms.StoreMessageInfo(mi) 228 | } 229 | } 230 | 231 | func (x *HelloReply) String() string { 232 | return protoimpl.X.MessageStringOf(x) 233 | } 234 | 235 | func (*HelloReply) ProtoMessage() {} 236 | 237 | func (x *HelloReply) ProtoReflect() protoreflect.Message { 238 | mi := &file_proto_helloworld_proto_msgTypes[2] 239 | if protoimpl.UnsafeEnabled && x != nil { 240 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 241 | if ms.LoadMessageInfo() == nil { 242 | ms.StoreMessageInfo(mi) 243 | } 244 | return ms 245 | } 246 | return mi.MessageOf(x) 247 | } 248 | 249 | // Deprecated: Use HelloReply.ProtoReflect.Descriptor instead. 250 | func (*HelloReply) Descriptor() ([]byte, []int) { 251 | return file_proto_helloworld_proto_rawDescGZIP(), []int{2} 252 | } 253 | 254 | func (x *HelloReply) GetMessage() string { 255 | if x != nil { 256 | return x.Message 257 | } 258 | return "" 259 | } 260 | 261 | func (x *HelloReply) GetItems() []string { 262 | if x != nil { 263 | return x.Items 264 | } 265 | return nil 266 | } 267 | 268 | func (x *HelloReply) GetGender() Gender { 269 | if x != nil { 270 | return x.Gender 271 | } 272 | return Gender_GENDER_UNKNOWN 273 | } 274 | 275 | type PlusRequest struct { 276 | state protoimpl.MessageState 277 | sizeCache protoimpl.SizeCache 278 | unknownFields protoimpl.UnknownFields 279 | 280 | A int64 `protobuf:"varint,1,opt,name=a,proto3" json:"a,omitempty"` 281 | B int64 `protobuf:"varint,2,opt,name=b,proto3" json:"b,omitempty"` 282 | } 283 | 284 | func (x *PlusRequest) Reset() { 285 | *x = PlusRequest{} 286 | if protoimpl.UnsafeEnabled { 287 | mi := &file_proto_helloworld_proto_msgTypes[3] 288 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 289 | ms.StoreMessageInfo(mi) 290 | } 291 | } 292 | 293 | func (x *PlusRequest) String() string { 294 | return protoimpl.X.MessageStringOf(x) 295 | } 296 | 297 | func (*PlusRequest) ProtoMessage() {} 298 | 299 | func (x *PlusRequest) ProtoReflect() protoreflect.Message { 300 | mi := &file_proto_helloworld_proto_msgTypes[3] 301 | if protoimpl.UnsafeEnabled && x != nil { 302 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 303 | if ms.LoadMessageInfo() == nil { 304 | ms.StoreMessageInfo(mi) 305 | } 306 | return ms 307 | } 308 | return mi.MessageOf(x) 309 | } 310 | 311 | // Deprecated: Use PlusRequest.ProtoReflect.Descriptor instead. 312 | func (*PlusRequest) Descriptor() ([]byte, []int) { 313 | return file_proto_helloworld_proto_rawDescGZIP(), []int{3} 314 | } 315 | 316 | func (x *PlusRequest) GetA() int64 { 317 | if x != nil { 318 | return x.A 319 | } 320 | return 0 321 | } 322 | 323 | func (x *PlusRequest) GetB() int64 { 324 | if x != nil { 325 | return x.B 326 | } 327 | return 0 328 | } 329 | 330 | type PlusReply struct { 331 | state protoimpl.MessageState 332 | sizeCache protoimpl.SizeCache 333 | unknownFields protoimpl.UnknownFields 334 | 335 | Result int64 `protobuf:"varint,1,opt,name=result,proto3" json:"result,omitempty"` 336 | } 337 | 338 | func (x *PlusReply) Reset() { 339 | *x = PlusReply{} 340 | if protoimpl.UnsafeEnabled { 341 | mi := &file_proto_helloworld_proto_msgTypes[4] 342 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 343 | ms.StoreMessageInfo(mi) 344 | } 345 | } 346 | 347 | func (x *PlusReply) String() string { 348 | return protoimpl.X.MessageStringOf(x) 349 | } 350 | 351 | func (*PlusReply) ProtoMessage() {} 352 | 353 | func (x *PlusReply) ProtoReflect() protoreflect.Message { 354 | mi := &file_proto_helloworld_proto_msgTypes[4] 355 | if protoimpl.UnsafeEnabled && x != nil { 356 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 357 | if ms.LoadMessageInfo() == nil { 358 | ms.StoreMessageInfo(mi) 359 | } 360 | return ms 361 | } 362 | return mi.MessageOf(x) 363 | } 364 | 365 | // Deprecated: Use PlusReply.ProtoReflect.Descriptor instead. 366 | func (*PlusReply) Descriptor() ([]byte, []int) { 367 | return file_proto_helloworld_proto_rawDescGZIP(), []int{4} 368 | } 369 | 370 | func (x *PlusReply) GetResult() int64 { 371 | if x != nil { 372 | return x.Result 373 | } 374 | return 0 375 | } 376 | 377 | type ErrorDetail struct { 378 | state protoimpl.MessageState 379 | sizeCache protoimpl.SizeCache 380 | unknownFields protoimpl.UnknownFields 381 | 382 | Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` 383 | Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` 384 | Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` 385 | } 386 | 387 | func (x *ErrorDetail) Reset() { 388 | *x = ErrorDetail{} 389 | if protoimpl.UnsafeEnabled { 390 | mi := &file_proto_helloworld_proto_msgTypes[5] 391 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 392 | ms.StoreMessageInfo(mi) 393 | } 394 | } 395 | 396 | func (x *ErrorDetail) String() string { 397 | return protoimpl.X.MessageStringOf(x) 398 | } 399 | 400 | func (*ErrorDetail) ProtoMessage() {} 401 | 402 | func (x *ErrorDetail) ProtoReflect() protoreflect.Message { 403 | mi := &file_proto_helloworld_proto_msgTypes[5] 404 | if protoimpl.UnsafeEnabled && x != nil { 405 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 406 | if ms.LoadMessageInfo() == nil { 407 | ms.StoreMessageInfo(mi) 408 | } 409 | return ms 410 | } 411 | return mi.MessageOf(x) 412 | } 413 | 414 | // Deprecated: Use ErrorDetail.ProtoReflect.Descriptor instead. 415 | func (*ErrorDetail) Descriptor() ([]byte, []int) { 416 | return file_proto_helloworld_proto_rawDescGZIP(), []int{5} 417 | } 418 | 419 | func (x *ErrorDetail) GetCode() int64 { 420 | if x != nil { 421 | return x.Code 422 | } 423 | return 0 424 | } 425 | 426 | func (x *ErrorDetail) GetMessage() string { 427 | if x != nil { 428 | return x.Message 429 | } 430 | return "" 431 | } 432 | 433 | func (x *ErrorDetail) GetType() string { 434 | if x != nil { 435 | return x.Type 436 | } 437 | return "" 438 | } 439 | 440 | var File_proto_helloworld_proto protoreflect.FileDescriptor 441 | 442 | var file_proto_helloworld_proto_rawDesc = []byte{ 443 | 0x0a, 0x16, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 444 | 0x6c, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 445 | 0x6f, 0x72, 0x6c, 0x64, 0x22, 0x2e, 0x0a, 0x06, 0x50, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x12, 0x12, 446 | 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 447 | 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 448 | 0x03, 0x61, 0x67, 0x65, 0x22, 0x90, 0x01, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 449 | 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 450 | 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x65, 451 | 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x12, 452 | 0x2a, 0x0a, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 453 | 0x12, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x47, 0x65, 0x6e, 454 | 0x64, 0x65, 0x72, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x2a, 0x0a, 0x06, 0x70, 455 | 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x68, 0x65, 456 | 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x50, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x52, 457 | 0x06, 0x70, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x22, 0x68, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 458 | 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 459 | 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 460 | 0x14, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 461 | 0x69, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x2a, 0x0a, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 462 | 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 463 | 0x6c, 0x64, 0x2e, 0x47, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 464 | 0x72, 0x22, 0x29, 0x0a, 0x0b, 0x50, 0x6c, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 465 | 0x12, 0x0c, 0x0a, 0x01, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x01, 0x61, 0x12, 0x0c, 466 | 0x0a, 0x01, 0x62, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x01, 0x62, 0x22, 0x23, 0x0a, 0x09, 467 | 0x50, 0x6c, 0x75, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 468 | 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 469 | 0x74, 0x22, 0x4f, 0x0a, 0x0b, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 470 | 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 471 | 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 472 | 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 473 | 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 474 | 0x70, 0x65, 0x2a, 0x40, 0x0a, 0x06, 0x47, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x0e, 475 | 0x47, 0x45, 0x4e, 0x44, 0x45, 0x52, 0x5f, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 476 | 0x12, 0x0f, 0x0a, 0x0b, 0x47, 0x45, 0x4e, 0x44, 0x45, 0x52, 0x5f, 0x4d, 0x41, 0x4c, 0x45, 0x10, 477 | 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x47, 0x45, 0x4e, 0x44, 0x45, 0x52, 0x5f, 0x46, 0x45, 0x4d, 0x41, 478 | 0x4c, 0x45, 0x10, 0x02, 0x32, 0x82, 0x04, 0x0a, 0x07, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 479 | 0x12, 0x3e, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x18, 0x2e, 0x68, 480 | 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 481 | 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 482 | 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 483 | 0x12, 0x40, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x45, 0x72, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 484 | 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 485 | 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 486 | 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 487 | 0x22, 0x00, 0x12, 0x38, 0x0a, 0x04, 0x50, 0x6c, 0x75, 0x73, 0x12, 0x17, 0x2e, 0x68, 0x65, 0x6c, 488 | 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x50, 0x6c, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 489 | 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 490 | 0x2e, 0x50, 0x6c, 0x75, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x12, 491 | 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x41, 0x66, 0x74, 0x65, 0x72, 0x44, 0x65, 0x6c, 492 | 0x61, 0x79, 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 493 | 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x68, 494 | 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 495 | 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x4c, 0x0a, 0x14, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 496 | 0x6c, 0x6f, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x18, 497 | 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 498 | 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 499 | 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 500 | 0x22, 0x00, 0x30, 0x01, 0x12, 0x4c, 0x0a, 0x14, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 501 | 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x18, 0x2e, 0x68, 502 | 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 503 | 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 504 | 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 505 | 0x28, 0x01, 0x12, 0x55, 0x0a, 0x1b, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x42, 0x69, 506 | 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x53, 0x74, 0x72, 0x65, 0x61, 507 | 0x6d, 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 508 | 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x68, 0x65, 509 | 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 510 | 0x70, 0x6c, 0x79, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x70, 511 | 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 512 | } 513 | 514 | var ( 515 | file_proto_helloworld_proto_rawDescOnce sync.Once 516 | file_proto_helloworld_proto_rawDescData = file_proto_helloworld_proto_rawDesc 517 | ) 518 | 519 | func file_proto_helloworld_proto_rawDescGZIP() []byte { 520 | file_proto_helloworld_proto_rawDescOnce.Do(func() { 521 | file_proto_helloworld_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_helloworld_proto_rawDescData) 522 | }) 523 | return file_proto_helloworld_proto_rawDescData 524 | } 525 | 526 | var file_proto_helloworld_proto_enumTypes = make([]protoimpl.EnumInfo, 1) 527 | var file_proto_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 6) 528 | var file_proto_helloworld_proto_goTypes = []interface{}{ 529 | (Gender)(0), // 0: helloworld.Gender 530 | (*Person)(nil), // 1: helloworld.Person 531 | (*HelloRequest)(nil), // 2: helloworld.HelloRequest 532 | (*HelloReply)(nil), // 3: helloworld.HelloReply 533 | (*PlusRequest)(nil), // 4: helloworld.PlusRequest 534 | (*PlusReply)(nil), // 5: helloworld.PlusReply 535 | (*ErrorDetail)(nil), // 6: helloworld.ErrorDetail 536 | } 537 | var file_proto_helloworld_proto_depIdxs = []int32{ 538 | 0, // 0: helloworld.HelloRequest.gender:type_name -> helloworld.Gender 539 | 1, // 1: helloworld.HelloRequest.person:type_name -> helloworld.Person 540 | 0, // 2: helloworld.HelloReply.gender:type_name -> helloworld.Gender 541 | 2, // 3: helloworld.Greeter.SayHello:input_type -> helloworld.HelloRequest 542 | 2, // 4: helloworld.Greeter.GetErrResp:input_type -> helloworld.HelloRequest 543 | 4, // 5: helloworld.Greeter.Plus:input_type -> helloworld.PlusRequest 544 | 2, // 6: helloworld.Greeter.SayHelloAfterDelay:input_type -> helloworld.HelloRequest 545 | 2, // 7: helloworld.Greeter.SayHelloServerStream:input_type -> helloworld.HelloRequest 546 | 2, // 8: helloworld.Greeter.SayHelloClientStream:input_type -> helloworld.HelloRequest 547 | 2, // 9: helloworld.Greeter.SayHelloBidirectionalStream:input_type -> helloworld.HelloRequest 548 | 3, // 10: helloworld.Greeter.SayHello:output_type -> helloworld.HelloReply 549 | 3, // 11: helloworld.Greeter.GetErrResp:output_type -> helloworld.HelloReply 550 | 5, // 12: helloworld.Greeter.Plus:output_type -> helloworld.PlusReply 551 | 3, // 13: helloworld.Greeter.SayHelloAfterDelay:output_type -> helloworld.HelloReply 552 | 3, // 14: helloworld.Greeter.SayHelloServerStream:output_type -> helloworld.HelloReply 553 | 3, // 15: helloworld.Greeter.SayHelloClientStream:output_type -> helloworld.HelloReply 554 | 3, // 16: helloworld.Greeter.SayHelloBidirectionalStream:output_type -> helloworld.HelloReply 555 | 10, // [10:17] is the sub-list for method output_type 556 | 3, // [3:10] is the sub-list for method input_type 557 | 3, // [3:3] is the sub-list for extension type_name 558 | 3, // [3:3] is the sub-list for extension extendee 559 | 0, // [0:3] is the sub-list for field type_name 560 | } 561 | 562 | func init() { file_proto_helloworld_proto_init() } 563 | func file_proto_helloworld_proto_init() { 564 | if File_proto_helloworld_proto != nil { 565 | return 566 | } 567 | if !protoimpl.UnsafeEnabled { 568 | file_proto_helloworld_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 569 | switch v := v.(*Person); i { 570 | case 0: 571 | return &v.state 572 | case 1: 573 | return &v.sizeCache 574 | case 2: 575 | return &v.unknownFields 576 | default: 577 | return nil 578 | } 579 | } 580 | file_proto_helloworld_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 581 | switch v := v.(*HelloRequest); i { 582 | case 0: 583 | return &v.state 584 | case 1: 585 | return &v.sizeCache 586 | case 2: 587 | return &v.unknownFields 588 | default: 589 | return nil 590 | } 591 | } 592 | file_proto_helloworld_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { 593 | switch v := v.(*HelloReply); i { 594 | case 0: 595 | return &v.state 596 | case 1: 597 | return &v.sizeCache 598 | case 2: 599 | return &v.unknownFields 600 | default: 601 | return nil 602 | } 603 | } 604 | file_proto_helloworld_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { 605 | switch v := v.(*PlusRequest); i { 606 | case 0: 607 | return &v.state 608 | case 1: 609 | return &v.sizeCache 610 | case 2: 611 | return &v.unknownFields 612 | default: 613 | return nil 614 | } 615 | } 616 | file_proto_helloworld_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { 617 | switch v := v.(*PlusReply); i { 618 | case 0: 619 | return &v.state 620 | case 1: 621 | return &v.sizeCache 622 | case 2: 623 | return &v.unknownFields 624 | default: 625 | return nil 626 | } 627 | } 628 | file_proto_helloworld_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { 629 | switch v := v.(*ErrorDetail); i { 630 | case 0: 631 | return &v.state 632 | case 1: 633 | return &v.sizeCache 634 | case 2: 635 | return &v.unknownFields 636 | default: 637 | return nil 638 | } 639 | } 640 | } 641 | type x struct{} 642 | out := protoimpl.TypeBuilder{ 643 | File: protoimpl.DescBuilder{ 644 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 645 | RawDescriptor: file_proto_helloworld_proto_rawDesc, 646 | NumEnums: 1, 647 | NumMessages: 6, 648 | NumExtensions: 0, 649 | NumServices: 1, 650 | }, 651 | GoTypes: file_proto_helloworld_proto_goTypes, 652 | DependencyIndexes: file_proto_helloworld_proto_depIdxs, 653 | EnumInfos: file_proto_helloworld_proto_enumTypes, 654 | MessageInfos: file_proto_helloworld_proto_msgTypes, 655 | }.Build() 656 | File_proto_helloworld_proto = out.File 657 | file_proto_helloworld_proto_rawDesc = nil 658 | file_proto_helloworld_proto_goTypes = nil 659 | file_proto_helloworld_proto_depIdxs = nil 660 | } 661 | -------------------------------------------------------------------------------- /proto/helloworld.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package helloworld; 18 | option go_package = "./proto"; 19 | 20 | service Greeter { 21 | // Unary RPC. 22 | rpc SayHello (HelloRequest) returns (HelloReply) {} 23 | rpc GetErrResp (HelloRequest) returns (HelloReply) {} 24 | rpc Plus (PlusRequest) returns (PlusReply) {} 25 | rpc SayHelloAfterDelay (HelloRequest) returns (HelloReply) {} 26 | 27 | // Server side streaming. 28 | rpc SayHelloServerStream (HelloRequest) returns (stream HelloReply) {} 29 | 30 | // Client side streaming. 31 | rpc SayHelloClientStream (stream HelloRequest) returns (HelloReply) {} 32 | 33 | // Bidirectional streaming. 34 | rpc SayHelloBidirectionalStream (stream HelloRequest) returns (stream HelloReply) {} 35 | } 36 | 37 | enum Gender { 38 | GENDER_UNKNOWN = 0; 39 | GENDER_MALE = 1; 40 | GENDER_FEMALE = 2; 41 | } 42 | 43 | message Person { 44 | string name = 1; 45 | int32 age = 2; 46 | } 47 | 48 | message HelloRequest { 49 | string name = 1; 50 | repeated string items = 2; 51 | Gender gender = 3; 52 | Person person = 4; 53 | } 54 | 55 | message HelloReply { 56 | string message = 1; 57 | repeated string items = 2; 58 | Gender gender = 3; 59 | } 60 | 61 | message PlusRequest { 62 | int64 a = 1; 63 | int64 b = 2; 64 | } 65 | 66 | message PlusReply { 67 | int64 result = 1; 68 | } 69 | 70 | message ErrorDetail { 71 | int64 code = 1; 72 | string message = 2; 73 | string type = 3; 74 | } 75 | -------------------------------------------------------------------------------- /proto/helloworld_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-grpc v1.2.0 4 | // - protoc v3.21.12 5 | // source: proto/helloworld.proto 6 | 7 | package proto 8 | 9 | import ( 10 | context "context" 11 | grpc "google.golang.org/grpc" 12 | codes "google.golang.org/grpc/codes" 13 | status "google.golang.org/grpc/status" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the grpc package it is being compiled against. 18 | // Requires gRPC-Go v1.32.0 or later. 19 | const _ = grpc.SupportPackageIsVersion7 20 | 21 | // GreeterClient is the client API for Greeter service. 22 | // 23 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 24 | type GreeterClient interface { 25 | // Unary RPC. 26 | SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) 27 | GetErrResp(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) 28 | Plus(ctx context.Context, in *PlusRequest, opts ...grpc.CallOption) (*PlusReply, error) 29 | SayHelloAfterDelay(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) 30 | // Server side streaming. 31 | SayHelloServerStream(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (Greeter_SayHelloServerStreamClient, error) 32 | // Client side streaming. 33 | SayHelloClientStream(ctx context.Context, opts ...grpc.CallOption) (Greeter_SayHelloClientStreamClient, error) 34 | // Bidirectional streaming. 35 | SayHelloBidirectionalStream(ctx context.Context, opts ...grpc.CallOption) (Greeter_SayHelloBidirectionalStreamClient, error) 36 | } 37 | 38 | type greeterClient struct { 39 | cc grpc.ClientConnInterface 40 | } 41 | 42 | func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient { 43 | return &greeterClient{cc} 44 | } 45 | 46 | func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { 47 | out := new(HelloReply) 48 | err := c.cc.Invoke(ctx, "/helloworld.Greeter/SayHello", in, out, opts...) 49 | if err != nil { 50 | return nil, err 51 | } 52 | return out, nil 53 | } 54 | 55 | func (c *greeterClient) GetErrResp(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { 56 | out := new(HelloReply) 57 | err := c.cc.Invoke(ctx, "/helloworld.Greeter/GetErrResp", in, out, opts...) 58 | if err != nil { 59 | return nil, err 60 | } 61 | return out, nil 62 | } 63 | 64 | func (c *greeterClient) Plus(ctx context.Context, in *PlusRequest, opts ...grpc.CallOption) (*PlusReply, error) { 65 | out := new(PlusReply) 66 | err := c.cc.Invoke(ctx, "/helloworld.Greeter/Plus", in, out, opts...) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return out, nil 71 | } 72 | 73 | func (c *greeterClient) SayHelloAfterDelay(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { 74 | out := new(HelloReply) 75 | err := c.cc.Invoke(ctx, "/helloworld.Greeter/SayHelloAfterDelay", in, out, opts...) 76 | if err != nil { 77 | return nil, err 78 | } 79 | return out, nil 80 | } 81 | 82 | func (c *greeterClient) SayHelloServerStream(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (Greeter_SayHelloServerStreamClient, error) { 83 | stream, err := c.cc.NewStream(ctx, &Greeter_ServiceDesc.Streams[0], "/helloworld.Greeter/SayHelloServerStream", opts...) 84 | if err != nil { 85 | return nil, err 86 | } 87 | x := &greeterSayHelloServerStreamClient{stream} 88 | if err := x.ClientStream.SendMsg(in); err != nil { 89 | return nil, err 90 | } 91 | if err := x.ClientStream.CloseSend(); err != nil { 92 | return nil, err 93 | } 94 | return x, nil 95 | } 96 | 97 | type Greeter_SayHelloServerStreamClient interface { 98 | Recv() (*HelloReply, error) 99 | grpc.ClientStream 100 | } 101 | 102 | type greeterSayHelloServerStreamClient struct { 103 | grpc.ClientStream 104 | } 105 | 106 | func (x *greeterSayHelloServerStreamClient) Recv() (*HelloReply, error) { 107 | m := new(HelloReply) 108 | if err := x.ClientStream.RecvMsg(m); err != nil { 109 | return nil, err 110 | } 111 | return m, nil 112 | } 113 | 114 | func (c *greeterClient) SayHelloClientStream(ctx context.Context, opts ...grpc.CallOption) (Greeter_SayHelloClientStreamClient, error) { 115 | stream, err := c.cc.NewStream(ctx, &Greeter_ServiceDesc.Streams[1], "/helloworld.Greeter/SayHelloClientStream", opts...) 116 | if err != nil { 117 | return nil, err 118 | } 119 | x := &greeterSayHelloClientStreamClient{stream} 120 | return x, nil 121 | } 122 | 123 | type Greeter_SayHelloClientStreamClient interface { 124 | Send(*HelloRequest) error 125 | CloseAndRecv() (*HelloReply, error) 126 | grpc.ClientStream 127 | } 128 | 129 | type greeterSayHelloClientStreamClient struct { 130 | grpc.ClientStream 131 | } 132 | 133 | func (x *greeterSayHelloClientStreamClient) Send(m *HelloRequest) error { 134 | return x.ClientStream.SendMsg(m) 135 | } 136 | 137 | func (x *greeterSayHelloClientStreamClient) CloseAndRecv() (*HelloReply, error) { 138 | if err := x.ClientStream.CloseSend(); err != nil { 139 | return nil, err 140 | } 141 | m := new(HelloReply) 142 | if err := x.ClientStream.RecvMsg(m); err != nil { 143 | return nil, err 144 | } 145 | return m, nil 146 | } 147 | 148 | func (c *greeterClient) SayHelloBidirectionalStream(ctx context.Context, opts ...grpc.CallOption) (Greeter_SayHelloBidirectionalStreamClient, error) { 149 | stream, err := c.cc.NewStream(ctx, &Greeter_ServiceDesc.Streams[2], "/helloworld.Greeter/SayHelloBidirectionalStream", opts...) 150 | if err != nil { 151 | return nil, err 152 | } 153 | x := &greeterSayHelloBidirectionalStreamClient{stream} 154 | return x, nil 155 | } 156 | 157 | type Greeter_SayHelloBidirectionalStreamClient interface { 158 | Send(*HelloRequest) error 159 | Recv() (*HelloReply, error) 160 | grpc.ClientStream 161 | } 162 | 163 | type greeterSayHelloBidirectionalStreamClient struct { 164 | grpc.ClientStream 165 | } 166 | 167 | func (x *greeterSayHelloBidirectionalStreamClient) Send(m *HelloRequest) error { 168 | return x.ClientStream.SendMsg(m) 169 | } 170 | 171 | func (x *greeterSayHelloBidirectionalStreamClient) Recv() (*HelloReply, error) { 172 | m := new(HelloReply) 173 | if err := x.ClientStream.RecvMsg(m); err != nil { 174 | return nil, err 175 | } 176 | return m, nil 177 | } 178 | 179 | // GreeterServer is the server API for Greeter service. 180 | // All implementations must embed UnimplementedGreeterServer 181 | // for forward compatibility 182 | type GreeterServer interface { 183 | // Unary RPC. 184 | SayHello(context.Context, *HelloRequest) (*HelloReply, error) 185 | GetErrResp(context.Context, *HelloRequest) (*HelloReply, error) 186 | Plus(context.Context, *PlusRequest) (*PlusReply, error) 187 | SayHelloAfterDelay(context.Context, *HelloRequest) (*HelloReply, error) 188 | // Server side streaming. 189 | SayHelloServerStream(*HelloRequest, Greeter_SayHelloServerStreamServer) error 190 | // Client side streaming. 191 | SayHelloClientStream(Greeter_SayHelloClientStreamServer) error 192 | // Bidirectional streaming. 193 | SayHelloBidirectionalStream(Greeter_SayHelloBidirectionalStreamServer) error 194 | mustEmbedUnimplementedGreeterServer() 195 | } 196 | 197 | // UnimplementedGreeterServer must be embedded to have forward compatible implementations. 198 | type UnimplementedGreeterServer struct { 199 | } 200 | 201 | func (UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { 202 | return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") 203 | } 204 | func (UnimplementedGreeterServer) GetErrResp(context.Context, *HelloRequest) (*HelloReply, error) { 205 | return nil, status.Errorf(codes.Unimplemented, "method GetErrResp not implemented") 206 | } 207 | func (UnimplementedGreeterServer) Plus(context.Context, *PlusRequest) (*PlusReply, error) { 208 | return nil, status.Errorf(codes.Unimplemented, "method Plus not implemented") 209 | } 210 | func (UnimplementedGreeterServer) SayHelloAfterDelay(context.Context, *HelloRequest) (*HelloReply, error) { 211 | return nil, status.Errorf(codes.Unimplemented, "method SayHelloAfterDelay not implemented") 212 | } 213 | func (UnimplementedGreeterServer) SayHelloServerStream(*HelloRequest, Greeter_SayHelloServerStreamServer) error { 214 | return status.Errorf(codes.Unimplemented, "method SayHelloServerStream not implemented") 215 | } 216 | func (UnimplementedGreeterServer) SayHelloClientStream(Greeter_SayHelloClientStreamServer) error { 217 | return status.Errorf(codes.Unimplemented, "method SayHelloClientStream not implemented") 218 | } 219 | func (UnimplementedGreeterServer) SayHelloBidirectionalStream(Greeter_SayHelloBidirectionalStreamServer) error { 220 | return status.Errorf(codes.Unimplemented, "method SayHelloBidirectionalStream not implemented") 221 | } 222 | func (UnimplementedGreeterServer) mustEmbedUnimplementedGreeterServer() {} 223 | 224 | // UnsafeGreeterServer may be embedded to opt out of forward compatibility for this service. 225 | // Use of this interface is not recommended, as added methods to GreeterServer will 226 | // result in compilation errors. 227 | type UnsafeGreeterServer interface { 228 | mustEmbedUnimplementedGreeterServer() 229 | } 230 | 231 | func RegisterGreeterServer(s grpc.ServiceRegistrar, srv GreeterServer) { 232 | s.RegisterService(&Greeter_ServiceDesc, srv) 233 | } 234 | 235 | func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 236 | in := new(HelloRequest) 237 | if err := dec(in); err != nil { 238 | return nil, err 239 | } 240 | if interceptor == nil { 241 | return srv.(GreeterServer).SayHello(ctx, in) 242 | } 243 | info := &grpc.UnaryServerInfo{ 244 | Server: srv, 245 | FullMethod: "/helloworld.Greeter/SayHello", 246 | } 247 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 248 | return srv.(GreeterServer).SayHello(ctx, req.(*HelloRequest)) 249 | } 250 | return interceptor(ctx, in, info, handler) 251 | } 252 | 253 | func _Greeter_GetErrResp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 254 | in := new(HelloRequest) 255 | if err := dec(in); err != nil { 256 | return nil, err 257 | } 258 | if interceptor == nil { 259 | return srv.(GreeterServer).GetErrResp(ctx, in) 260 | } 261 | info := &grpc.UnaryServerInfo{ 262 | Server: srv, 263 | FullMethod: "/helloworld.Greeter/GetErrResp", 264 | } 265 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 266 | return srv.(GreeterServer).GetErrResp(ctx, req.(*HelloRequest)) 267 | } 268 | return interceptor(ctx, in, info, handler) 269 | } 270 | 271 | func _Greeter_Plus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 272 | in := new(PlusRequest) 273 | if err := dec(in); err != nil { 274 | return nil, err 275 | } 276 | if interceptor == nil { 277 | return srv.(GreeterServer).Plus(ctx, in) 278 | } 279 | info := &grpc.UnaryServerInfo{ 280 | Server: srv, 281 | FullMethod: "/helloworld.Greeter/Plus", 282 | } 283 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 284 | return srv.(GreeterServer).Plus(ctx, req.(*PlusRequest)) 285 | } 286 | return interceptor(ctx, in, info, handler) 287 | } 288 | 289 | func _Greeter_SayHelloAfterDelay_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 290 | in := new(HelloRequest) 291 | if err := dec(in); err != nil { 292 | return nil, err 293 | } 294 | if interceptor == nil { 295 | return srv.(GreeterServer).SayHelloAfterDelay(ctx, in) 296 | } 297 | info := &grpc.UnaryServerInfo{ 298 | Server: srv, 299 | FullMethod: "/helloworld.Greeter/SayHelloAfterDelay", 300 | } 301 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 302 | return srv.(GreeterServer).SayHelloAfterDelay(ctx, req.(*HelloRequest)) 303 | } 304 | return interceptor(ctx, in, info, handler) 305 | } 306 | 307 | func _Greeter_SayHelloServerStream_Handler(srv interface{}, stream grpc.ServerStream) error { 308 | m := new(HelloRequest) 309 | if err := stream.RecvMsg(m); err != nil { 310 | return err 311 | } 312 | return srv.(GreeterServer).SayHelloServerStream(m, &greeterSayHelloServerStreamServer{stream}) 313 | } 314 | 315 | type Greeter_SayHelloServerStreamServer interface { 316 | Send(*HelloReply) error 317 | grpc.ServerStream 318 | } 319 | 320 | type greeterSayHelloServerStreamServer struct { 321 | grpc.ServerStream 322 | } 323 | 324 | func (x *greeterSayHelloServerStreamServer) Send(m *HelloReply) error { 325 | return x.ServerStream.SendMsg(m) 326 | } 327 | 328 | func _Greeter_SayHelloClientStream_Handler(srv interface{}, stream grpc.ServerStream) error { 329 | return srv.(GreeterServer).SayHelloClientStream(&greeterSayHelloClientStreamServer{stream}) 330 | } 331 | 332 | type Greeter_SayHelloClientStreamServer interface { 333 | SendAndClose(*HelloReply) error 334 | Recv() (*HelloRequest, error) 335 | grpc.ServerStream 336 | } 337 | 338 | type greeterSayHelloClientStreamServer struct { 339 | grpc.ServerStream 340 | } 341 | 342 | func (x *greeterSayHelloClientStreamServer) SendAndClose(m *HelloReply) error { 343 | return x.ServerStream.SendMsg(m) 344 | } 345 | 346 | func (x *greeterSayHelloClientStreamServer) Recv() (*HelloRequest, error) { 347 | m := new(HelloRequest) 348 | if err := x.ServerStream.RecvMsg(m); err != nil { 349 | return nil, err 350 | } 351 | return m, nil 352 | } 353 | 354 | func _Greeter_SayHelloBidirectionalStream_Handler(srv interface{}, stream grpc.ServerStream) error { 355 | return srv.(GreeterServer).SayHelloBidirectionalStream(&greeterSayHelloBidirectionalStreamServer{stream}) 356 | } 357 | 358 | type Greeter_SayHelloBidirectionalStreamServer interface { 359 | Send(*HelloReply) error 360 | Recv() (*HelloRequest, error) 361 | grpc.ServerStream 362 | } 363 | 364 | type greeterSayHelloBidirectionalStreamServer struct { 365 | grpc.ServerStream 366 | } 367 | 368 | func (x *greeterSayHelloBidirectionalStreamServer) Send(m *HelloReply) error { 369 | return x.ServerStream.SendMsg(m) 370 | } 371 | 372 | func (x *greeterSayHelloBidirectionalStreamServer) Recv() (*HelloRequest, error) { 373 | m := new(HelloRequest) 374 | if err := x.ServerStream.RecvMsg(m); err != nil { 375 | return nil, err 376 | } 377 | return m, nil 378 | } 379 | 380 | // Greeter_ServiceDesc is the grpc.ServiceDesc for Greeter service. 381 | // It's only intended for direct use with grpc.RegisterService, 382 | // and not to be introspected or modified (even as a copy) 383 | var Greeter_ServiceDesc = grpc.ServiceDesc{ 384 | ServiceName: "helloworld.Greeter", 385 | HandlerType: (*GreeterServer)(nil), 386 | Methods: []grpc.MethodDesc{ 387 | { 388 | MethodName: "SayHello", 389 | Handler: _Greeter_SayHello_Handler, 390 | }, 391 | { 392 | MethodName: "GetErrResp", 393 | Handler: _Greeter_GetErrResp_Handler, 394 | }, 395 | { 396 | MethodName: "Plus", 397 | Handler: _Greeter_Plus_Handler, 398 | }, 399 | { 400 | MethodName: "SayHelloAfterDelay", 401 | Handler: _Greeter_SayHelloAfterDelay_Handler, 402 | }, 403 | }, 404 | Streams: []grpc.StreamDesc{ 405 | { 406 | StreamName: "SayHelloServerStream", 407 | Handler: _Greeter_SayHelloServerStream_Handler, 408 | ServerStreams: true, 409 | }, 410 | { 411 | StreamName: "SayHelloClientStream", 412 | Handler: _Greeter_SayHelloClientStream_Handler, 413 | ClientStreams: true, 414 | }, 415 | { 416 | StreamName: "SayHelloBidirectionalStream", 417 | Handler: _Greeter_SayHelloBidirectionalStream_Handler, 418 | ServerStreams: true, 419 | ClientStreams: true, 420 | }, 421 | }, 422 | Metadata: "proto/helloworld.proto", 423 | } 424 | -------------------------------------------------------------------------------- /proto/import.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.27.1 4 | // protoc v3.6.1 5 | // source: proto/import.proto 6 | 7 | package proto 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type User struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` 29 | } 30 | 31 | func (x *User) Reset() { 32 | *x = User{} 33 | if protoimpl.UnsafeEnabled { 34 | mi := &file_proto_import_proto_msgTypes[0] 35 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 36 | ms.StoreMessageInfo(mi) 37 | } 38 | } 39 | 40 | func (x *User) String() string { 41 | return protoimpl.X.MessageStringOf(x) 42 | } 43 | 44 | func (*User) ProtoMessage() {} 45 | 46 | func (x *User) ProtoReflect() protoreflect.Message { 47 | mi := &file_proto_import_proto_msgTypes[0] 48 | if protoimpl.UnsafeEnabled && x != nil { 49 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 50 | if ms.LoadMessageInfo() == nil { 51 | ms.StoreMessageInfo(mi) 52 | } 53 | return ms 54 | } 55 | return mi.MessageOf(x) 56 | } 57 | 58 | // Deprecated: Use User.ProtoReflect.Descriptor instead. 59 | func (*User) Descriptor() ([]byte, []int) { 60 | return file_proto_import_proto_rawDescGZIP(), []int{0} 61 | } 62 | 63 | func (x *User) GetName() string { 64 | if x != nil { 65 | return x.Name 66 | } 67 | return "" 68 | } 69 | 70 | type Response struct { 71 | state protoimpl.MessageState 72 | sizeCache protoimpl.SizeCache 73 | unknownFields protoimpl.UnknownFields 74 | 75 | Body string `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` 76 | } 77 | 78 | func (x *Response) Reset() { 79 | *x = Response{} 80 | if protoimpl.UnsafeEnabled { 81 | mi := &file_proto_import_proto_msgTypes[1] 82 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 83 | ms.StoreMessageInfo(mi) 84 | } 85 | } 86 | 87 | func (x *Response) String() string { 88 | return protoimpl.X.MessageStringOf(x) 89 | } 90 | 91 | func (*Response) ProtoMessage() {} 92 | 93 | func (x *Response) ProtoReflect() protoreflect.Message { 94 | mi := &file_proto_import_proto_msgTypes[1] 95 | if protoimpl.UnsafeEnabled && x != nil { 96 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 97 | if ms.LoadMessageInfo() == nil { 98 | ms.StoreMessageInfo(mi) 99 | } 100 | return ms 101 | } 102 | return mi.MessageOf(x) 103 | } 104 | 105 | // Deprecated: Use Response.ProtoReflect.Descriptor instead. 106 | func (*Response) Descriptor() ([]byte, []int) { 107 | return file_proto_import_proto_rawDescGZIP(), []int{1} 108 | } 109 | 110 | func (x *Response) GetBody() string { 111 | if x != nil { 112 | return x.Body 113 | } 114 | return "" 115 | } 116 | 117 | var File_proto_import_proto protoreflect.FileDescriptor 118 | 119 | var file_proto_import_proto_rawDesc = []byte{ 120 | 0x0a, 0x12, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x70, 121 | 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x70, 0x6b, 0x67, 0x22, 0x1a, 0x0a, 0x04, 0x55, 0x73, 0x65, 122 | 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 123 | 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 124 | 0x65, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 125 | 0x04, 0x62, 0x6f, 0x64, 0x79, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 126 | 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 127 | } 128 | 129 | var ( 130 | file_proto_import_proto_rawDescOnce sync.Once 131 | file_proto_import_proto_rawDescData = file_proto_import_proto_rawDesc 132 | ) 133 | 134 | func file_proto_import_proto_rawDescGZIP() []byte { 135 | file_proto_import_proto_rawDescOnce.Do(func() { 136 | file_proto_import_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_import_proto_rawDescData) 137 | }) 138 | return file_proto_import_proto_rawDescData 139 | } 140 | 141 | var file_proto_import_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 142 | var file_proto_import_proto_goTypes = []interface{}{ 143 | (*User)(nil), // 0: pkg.User 144 | (*Response)(nil), // 1: pkg.Response 145 | } 146 | var file_proto_import_proto_depIdxs = []int32{ 147 | 0, // [0:0] is the sub-list for method output_type 148 | 0, // [0:0] is the sub-list for method input_type 149 | 0, // [0:0] is the sub-list for extension type_name 150 | 0, // [0:0] is the sub-list for extension extendee 151 | 0, // [0:0] is the sub-list for field type_name 152 | } 153 | 154 | func init() { file_proto_import_proto_init() } 155 | func file_proto_import_proto_init() { 156 | if File_proto_import_proto != nil { 157 | return 158 | } 159 | if !protoimpl.UnsafeEnabled { 160 | file_proto_import_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 161 | switch v := v.(*User); i { 162 | case 0: 163 | return &v.state 164 | case 1: 165 | return &v.sizeCache 166 | case 2: 167 | return &v.unknownFields 168 | default: 169 | return nil 170 | } 171 | } 172 | file_proto_import_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 173 | switch v := v.(*Response); i { 174 | case 0: 175 | return &v.state 176 | case 1: 177 | return &v.sizeCache 178 | case 2: 179 | return &v.unknownFields 180 | default: 181 | return nil 182 | } 183 | } 184 | } 185 | type x struct{} 186 | out := protoimpl.TypeBuilder{ 187 | File: protoimpl.DescBuilder{ 188 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 189 | RawDescriptor: file_proto_import_proto_rawDesc, 190 | NumEnums: 0, 191 | NumMessages: 2, 192 | NumExtensions: 0, 193 | NumServices: 0, 194 | }, 195 | GoTypes: file_proto_import_proto_goTypes, 196 | DependencyIndexes: file_proto_import_proto_depIdxs, 197 | MessageInfos: file_proto_import_proto_msgTypes, 198 | }.Build() 199 | File_proto_import_proto = out.File 200 | file_proto_import_proto_rawDesc = nil 201 | file_proto_import_proto_goTypes = nil 202 | file_proto_import_proto_depIdxs = nil 203 | } 204 | -------------------------------------------------------------------------------- /proto/import.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package pkg; 4 | option go_package = "./proto"; 5 | 6 | message User { 7 | string name = 1; 8 | } 9 | 10 | message Response { 11 | string body = 1; 12 | } 13 | -------------------------------------------------------------------------------- /proto/src.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.27.1 4 | // protoc v3.6.1 5 | // source: proto/src.proto 6 | 7 | package proto 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type Request struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` 29 | Body string `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"` 30 | } 31 | 32 | func (x *Request) Reset() { 33 | *x = Request{} 34 | if protoimpl.UnsafeEnabled { 35 | mi := &file_proto_src_proto_msgTypes[0] 36 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 37 | ms.StoreMessageInfo(mi) 38 | } 39 | } 40 | 41 | func (x *Request) String() string { 42 | return protoimpl.X.MessageStringOf(x) 43 | } 44 | 45 | func (*Request) ProtoMessage() {} 46 | 47 | func (x *Request) ProtoReflect() protoreflect.Message { 48 | mi := &file_proto_src_proto_msgTypes[0] 49 | if protoimpl.UnsafeEnabled && x != nil { 50 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 51 | if ms.LoadMessageInfo() == nil { 52 | ms.StoreMessageInfo(mi) 53 | } 54 | return ms 55 | } 56 | return mi.MessageOf(x) 57 | } 58 | 59 | // Deprecated: Use Request.ProtoReflect.Descriptor instead. 60 | func (*Request) Descriptor() ([]byte, []int) { 61 | return file_proto_src_proto_rawDescGZIP(), []int{0} 62 | } 63 | 64 | func (x *Request) GetUser() *User { 65 | if x != nil { 66 | return x.User 67 | } 68 | return nil 69 | } 70 | 71 | func (x *Request) GetBody() string { 72 | if x != nil { 73 | return x.Body 74 | } 75 | return "" 76 | } 77 | 78 | var File_proto_src_proto protoreflect.FileDescriptor 79 | 80 | var file_proto_src_proto_rawDesc = []byte{ 81 | 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x72, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 82 | 0x6f, 0x12, 0x0a, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x1a, 0x12, 0x70, 83 | 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 84 | 0x6f, 0x22, 0x3c, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x04, 85 | 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x70, 0x6b, 0x67, 86 | 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x62, 87 | 0x6f, 0x64, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x32, 88 | 0x39, 0x0a, 0x0a, 0x54, 0x65, 0x73, 0x74, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x2b, 0x0a, 89 | 0x03, 0x52, 0x75, 0x6e, 0x12, 0x13, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 90 | 0x64, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x70, 0x6b, 0x67, 0x2e, 91 | 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 92 | 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 93 | } 94 | 95 | var ( 96 | file_proto_src_proto_rawDescOnce sync.Once 97 | file_proto_src_proto_rawDescData = file_proto_src_proto_rawDesc 98 | ) 99 | 100 | func file_proto_src_proto_rawDescGZIP() []byte { 101 | file_proto_src_proto_rawDescOnce.Do(func() { 102 | file_proto_src_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_src_proto_rawDescData) 103 | }) 104 | return file_proto_src_proto_rawDescData 105 | } 106 | 107 | var file_proto_src_proto_msgTypes = make([]protoimpl.MessageInfo, 1) 108 | var file_proto_src_proto_goTypes = []interface{}{ 109 | (*Request)(nil), // 0: helloworld.Request 110 | (*User)(nil), // 1: pkg.User 111 | (*Response)(nil), // 2: pkg.Response 112 | } 113 | var file_proto_src_proto_depIdxs = []int32{ 114 | 1, // 0: helloworld.Request.user:type_name -> pkg.User 115 | 0, // 1: helloworld.TestImport.Run:input_type -> helloworld.Request 116 | 2, // 2: helloworld.TestImport.Run:output_type -> pkg.Response 117 | 2, // [2:3] is the sub-list for method output_type 118 | 1, // [1:2] is the sub-list for method input_type 119 | 1, // [1:1] is the sub-list for extension type_name 120 | 1, // [1:1] is the sub-list for extension extendee 121 | 0, // [0:1] is the sub-list for field type_name 122 | } 123 | 124 | func init() { file_proto_src_proto_init() } 125 | func file_proto_src_proto_init() { 126 | if File_proto_src_proto != nil { 127 | return 128 | } 129 | file_proto_import_proto_init() 130 | if !protoimpl.UnsafeEnabled { 131 | file_proto_src_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 132 | switch v := v.(*Request); i { 133 | case 0: 134 | return &v.state 135 | case 1: 136 | return &v.sizeCache 137 | case 2: 138 | return &v.unknownFields 139 | default: 140 | return nil 141 | } 142 | } 143 | } 144 | type x struct{} 145 | out := protoimpl.TypeBuilder{ 146 | File: protoimpl.DescBuilder{ 147 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 148 | RawDescriptor: file_proto_src_proto_rawDesc, 149 | NumEnums: 0, 150 | NumMessages: 1, 151 | NumExtensions: 0, 152 | NumServices: 1, 153 | }, 154 | GoTypes: file_proto_src_proto_goTypes, 155 | DependencyIndexes: file_proto_src_proto_depIdxs, 156 | MessageInfos: file_proto_src_proto_msgTypes, 157 | }.Build() 158 | File_proto_src_proto = out.File 159 | file_proto_src_proto_rawDesc = nil 160 | file_proto_src_proto_goTypes = nil 161 | file_proto_src_proto_depIdxs = nil 162 | } 163 | -------------------------------------------------------------------------------- /proto/src.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package helloworld; 4 | option go_package = "./proto"; 5 | 6 | import "proto/import.proto"; 7 | 8 | service TestImport { 9 | rpc Run (Request) returns (pkg.Response) {} 10 | } 11 | 12 | message Request { 13 | pkg.User user = 1; 14 | string body = 2; 15 | } 16 | -------------------------------------------------------------------------------- /proto/src_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | 3 | package proto 4 | 5 | import ( 6 | context "context" 7 | grpc "google.golang.org/grpc" 8 | codes "google.golang.org/grpc/codes" 9 | status "google.golang.org/grpc/status" 10 | ) 11 | 12 | // This is a compile-time assertion to ensure that this generated file 13 | // is compatible with the grpc package it is being compiled against. 14 | // Requires gRPC-Go v1.32.0 or later. 15 | const _ = grpc.SupportPackageIsVersion7 16 | 17 | // TestImportClient is the client API for TestImport service. 18 | // 19 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 20 | type TestImportClient interface { 21 | Run(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) 22 | } 23 | 24 | type testImportClient struct { 25 | cc grpc.ClientConnInterface 26 | } 27 | 28 | func NewTestImportClient(cc grpc.ClientConnInterface) TestImportClient { 29 | return &testImportClient{cc} 30 | } 31 | 32 | func (c *testImportClient) Run(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) { 33 | out := new(Response) 34 | err := c.cc.Invoke(ctx, "/helloworld.TestImport/Run", in, out, opts...) 35 | if err != nil { 36 | return nil, err 37 | } 38 | return out, nil 39 | } 40 | 41 | // TestImportServer is the server API for TestImport service. 42 | // All implementations must embed UnimplementedTestImportServer 43 | // for forward compatibility 44 | type TestImportServer interface { 45 | Run(context.Context, *Request) (*Response, error) 46 | mustEmbedUnimplementedTestImportServer() 47 | } 48 | 49 | // UnimplementedTestImportServer must be embedded to have forward compatible implementations. 50 | type UnimplementedTestImportServer struct { 51 | } 52 | 53 | func (UnimplementedTestImportServer) Run(context.Context, *Request) (*Response, error) { 54 | return nil, status.Errorf(codes.Unimplemented, "method Run not implemented") 55 | } 56 | func (UnimplementedTestImportServer) mustEmbedUnimplementedTestImportServer() {} 57 | 58 | // UnsafeTestImportServer may be embedded to opt out of forward compatibility for this service. 59 | // Use of this interface is not recommended, as added methods to TestImportServer will 60 | // result in compilation errors. 61 | type UnsafeTestImportServer interface { 62 | mustEmbedUnimplementedTestImportServer() 63 | } 64 | 65 | func RegisterTestImportServer(s grpc.ServiceRegistrar, srv TestImportServer) { 66 | s.RegisterService(&TestImport_ServiceDesc, srv) 67 | } 68 | 69 | func _TestImport_Run_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 70 | in := new(Request) 71 | if err := dec(in); err != nil { 72 | return nil, err 73 | } 74 | if interceptor == nil { 75 | return srv.(TestImportServer).Run(ctx, in) 76 | } 77 | info := &grpc.UnaryServerInfo{ 78 | Server: srv, 79 | FullMethod: "/helloworld.TestImport/Run", 80 | } 81 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 82 | return srv.(TestImportServer).Run(ctx, req.(*Request)) 83 | } 84 | return interceptor(ctx, in, info, handler) 85 | } 86 | 87 | // TestImport_ServiceDesc is the grpc.ServiceDesc for TestImport service. 88 | // It's only intended for direct use with grpc.RegisterService, 89 | // and not to be introspected or modified (even as a copy) 90 | var TestImport_ServiceDesc = grpc.ServiceDesc{ 91 | ServiceName: "helloworld.TestImport", 92 | HandlerType: (*TestImportServer)(nil), 93 | Methods: []grpc.MethodDesc{ 94 | { 95 | MethodName: "Run", 96 | Handler: _TestImport_Run_Handler, 97 | }, 98 | }, 99 | Streams: []grpc.StreamDesc{}, 100 | Metadata: "proto/src.proto", 101 | } 102 | -------------------------------------------------------------------------------- /t/cert/apisix.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEojCCAwqgAwIBAgIJAK253pMhgCkxMA0GCSqGSIb3DQEBCwUAMFYxCzAJBgNV 3 | BAYTAkNOMRIwEAYDVQQIDAlHdWFuZ0RvbmcxDzANBgNVBAcMBlpodUhhaTEPMA0G 4 | A1UECgwGaXJlc3R5MREwDwYDVQQDDAh0ZXN0LmNvbTAgFw0xOTA2MjQyMjE4MDVa 5 | GA8yMTE5MDUzMTIyMTgwNVowVjELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCUd1YW5n 6 | RG9uZzEPMA0GA1UEBwwGWmh1SGFpMQ8wDQYDVQQKDAZpcmVzdHkxETAPBgNVBAMM 7 | CHRlc3QuY29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAyCM0rqJe 8 | cvgnCfOw4fATotPwk5Ba0gC2YvIrO+gSbQkyxXF5jhZB3W6BkWUWR4oNFLLSqcVb 9 | VDPitz/Mt46Mo8amuS6zTbQetGnBARzPLtmVhJfoeLj0efMiOepOSZflj9Ob4yKR 10 | 2bGdEFOdHPjm+4ggXU9jMKeLqdVvxll/JiVFBW5smPtW1Oc/BV5terhscJdOgmRr 11 | abf9xiIis9/qVYfyGn52u9452V0owUuwP7nZ01jt6iMWEGeQU6mwPENgvj1olji2 12 | WjdG2UwpUVp3jp3l7j1ekQ6mI0F7yI+LeHzfUwiyVt1TmtMWn1ztk6FfLRqwJWR/ 13 | Evm95vnfS3Le4S2ky3XAgn2UnCMyej3wDN6qHR1onpRVeXhrBajbCRDRBMwaNw/1 14 | /3Uvza8QKK10PzQR6OcQ0xo9psMkd9j9ts/dTuo2fzaqpIfyUbPST4GdqNG9NyIh 15 | /B9g26/0EWcjyO7mYVkaycrtLMaXm1u9jyRmcQQI1cGrGwyXbrieNp63AgMBAAGj 16 | cTBvMB0GA1UdDgQWBBSZtSvV8mBwl0bpkvFtgyiOUUcbszAfBgNVHSMEGDAWgBSZ 17 | tSvV8mBwl0bpkvFtgyiOUUcbszAMBgNVHRMEBTADAQH/MB8GA1UdEQQYMBaCCHRl 18 | c3QuY29tggoqLnRlc3QuY29tMA0GCSqGSIb3DQEBCwUAA4IBgQAHGEul/x7ViVgC 19 | tC8CbXEslYEkj1XVr2Y4hXZXAXKd3W7V3TC8rqWWBbr6L/tsSVFt126V5WyRmOaY 20 | 1A5pju8VhnkhYxYfZALQxJN2tZPFVeME9iGJ9BE1wPtpMgITX8Rt9kbNlENfAgOl 21 | PYzrUZN1YUQjX+X8t8/1VkSmyZysr6ngJ46/M8F16gfYXc9zFj846Z9VST0zCKob 22 | rJs3GtHOkS9zGGldqKKCj+Awl0jvTstI4qtS1ED92tcnJh5j/SSXCAB5FgnpKZWy 23 | hme45nBQj86rJ8FhN+/aQ9H9/2Ib6Q4wbpaIvf4lQdLUEcWAeZGW6Rk0JURwEog1 24 | 7/mMgkapDglgeFx9f/XztSTrkHTaX4Obr+nYrZ2V4KOB4llZnK5GeNjDrOOJDk2y 25 | IJFgBOZJWyS93dQfuKEj42hA79MuX64lMSCVQSjX+ipR289GQZqFrIhiJxLyA+Ve 26 | U/OOcSRr39Kuis/JJ+DkgHYa/PWHZhnJQBxcqXXk1bJGw9BNbhM= 27 | -----END CERTIFICATE----- 28 | -------------------------------------------------------------------------------- /t/cert/apisix.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIG5AIBAAKCAYEAyCM0rqJecvgnCfOw4fATotPwk5Ba0gC2YvIrO+gSbQkyxXF5 3 | jhZB3W6BkWUWR4oNFLLSqcVbVDPitz/Mt46Mo8amuS6zTbQetGnBARzPLtmVhJfo 4 | eLj0efMiOepOSZflj9Ob4yKR2bGdEFOdHPjm+4ggXU9jMKeLqdVvxll/JiVFBW5s 5 | mPtW1Oc/BV5terhscJdOgmRrabf9xiIis9/qVYfyGn52u9452V0owUuwP7nZ01jt 6 | 6iMWEGeQU6mwPENgvj1olji2WjdG2UwpUVp3jp3l7j1ekQ6mI0F7yI+LeHzfUwiy 7 | Vt1TmtMWn1ztk6FfLRqwJWR/Evm95vnfS3Le4S2ky3XAgn2UnCMyej3wDN6qHR1o 8 | npRVeXhrBajbCRDRBMwaNw/1/3Uvza8QKK10PzQR6OcQ0xo9psMkd9j9ts/dTuo2 9 | fzaqpIfyUbPST4GdqNG9NyIh/B9g26/0EWcjyO7mYVkaycrtLMaXm1u9jyRmcQQI 10 | 1cGrGwyXbrieNp63AgMBAAECggGBAJM8g0duoHmIYoAJzbmKe4ew0C5fZtFUQNmu 11 | O2xJITUiLT3ga4LCkRYsdBnY+nkK8PCnViAb10KtIT+bKipoLsNWI9Xcq4Cg4G3t 12 | 11XQMgPPgxYXA6m8t+73ldhxrcKqgvI6xVZmWlKDPn+CY/Wqj5PA476B5wEmYbNC 13 | GIcd1FLl3E9Qm4g4b/sVXOHARF6iSvTR+6ol4nfWKlaXSlx2gNkHuG8RVpyDsp9c 14 | z9zUqAdZ3QyFQhKcWWEcL6u9DLBpB/gUjyB3qWhDMe7jcCBZR1ALyRyEjmDwZzv2 15 | jlv8qlLFfn9R29UI0pbuL1eRAz97scFOFme1s9oSU9a12YHfEd2wJOM9bqiKju8y 16 | DZzePhEYuTZ8qxwiPJGy7XvRYTGHAs8+iDlG4vVpA0qD++1FTpv06cg/fOdnwshE 17 | OJlEC0ozMvnM2rZ2oYejdG3aAnUHmSNa5tkJwXnmj/EMw1TEXf+H6+xknAkw05nh 18 | zsxXrbuFUe7VRfgB5ElMA/V4NsScgQKBwQDmMRtnS32UZjw4A8DsHOKFzugfWzJ8 19 | Gc+3sTgs+4dNIAvo0sjibQ3xl01h0BB2Pr1KtkgBYB8LJW/FuYdCRS/KlXH7PHgX 20 | 84gYWImhNhcNOL3coO8NXvd6+m+a/Z7xghbQtaraui6cDWPiCNd/sdLMZQ/7LopM 21 | RbM32nrgBKMOJpMok1Z6zsPzT83SjkcSxjVzgULNYEp03uf1PWmHuvjO1yELwX9/ 22 | goACViF+jst12RUEiEQIYwr4y637GQBy+9cCgcEA3pN9W5OjSPDVsTcVERig8++O 23 | BFURiUa7nXRHzKp2wT6jlMVcu8Pb2fjclxRyaMGYKZBRuXDlc/RNO3uTytGYNdC2 24 | IptU5N4M7iZHXj190xtDxRnYQWWo/PR6EcJj3f/tc3Itm1rX0JfuI3JzJQgDb9Z2 25 | s/9/ub8RRvmQV9LM/utgyOwNdf5dyVoPcTY2739X4ZzXNH+CybfNa+LWpiJIVEs2 26 | txXbgZrhmlaWzwA525nZ0UlKdfktdcXeqke9eBghAoHARVTHFy6CjV7ZhlmDEtqE 27 | U58FBOS36O7xRDdpXwsHLnCXhbFu9du41mom0W4UdzjgVI9gUqG71+SXrKr7lTc3 28 | dMHcSbplxXkBJawND/Q1rzLG5JvIRHO1AGJLmRgIdl8jNgtxgV2QSkoyKlNVbM2H 29 | Wy6ZSKM03lIj74+rcKuU3N87dX4jDuwV0sPXjzJxL7NpR/fHwgndgyPcI14y2cGz 30 | zMC44EyQdTw+B/YfMnoZx83xaaMNMqV6GYNnTHi0TO2TAoHBAKmdrh9WkE2qsr59 31 | IoHHygh7Wzez+Ewr6hfgoEK4+QzlBlX+XV/9rxIaE0jS3Sk1txadk5oFDebimuSk 32 | lQkv1pXUOqh+xSAwk5v88dBAfh2dnnSa8HFN3oz+ZfQYtnBcc4DR1y2X+fVNgr3i 33 | nxruU2gsAIPFRnmvwKPc1YIH9A6kIzqaoNt1f9VM243D6fNzkO4uztWEApBkkJgR 34 | 4s/yOjp6ovS9JG1NMXWjXQPcwTq3sQVLnAHxZRJmOvx69UmK4QKBwFYXXjeXiU3d 35 | bcrPfe6qNGjfzK+BkhWznuFUMbuxyZWDYQD5yb6ukUosrj7pmZv3BxKcKCvmONU+ 36 | CHgIXB+hG+R9S2mCcH1qBQoP/RSm+TUzS/Bl2UeuhnFZh2jSZQy3OwryUi6nhF0u 37 | LDzMI/6aO1ggsI23Ri0Y9ZtqVKczTkxzdQKR9xvoNBUufjimRlS80sJCEB3Qm20S 38 | wzarryret/7GFW1/3cz+hTj9/d45i25zArr3Pocfpur5mfz3fJO8jg== 39 | -----END RSA PRIVATE KEY----- 40 | --------------------------------------------------------------------------------