{"id":22885031,"url":"https://github.com/mark8s/go-grpc-examples","last_synced_at":"2025-03-31T17:55:28.322Z","repository":{"id":165211536,"uuid":"640202169","full_name":"mark8s/go-grpc-examples","owner":"mark8s","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-14T14:51:20.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T22:42:24.710Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mark8s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"security/README.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-13T10:13:45.000Z","updated_at":"2023-05-13T15:35:11.000Z","dependencies_parsed_at":"2023-06-27T17:24:51.702Z","dependency_job_id":null,"html_url":"https://github.com/mark8s/go-grpc-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark8s%2Fgo-grpc-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark8s%2Fgo-grpc-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark8s%2Fgo-grpc-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark8s%2Fgo-grpc-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mark8s","download_url":"https://codeload.github.com/mark8s/go-grpc-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246514265,"owners_count":20790016,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T19:31:05.282Z","updated_at":"2025-03-31T17:55:28.278Z","avatar_url":"https://github.com/mark8s.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-grpc-examples\n\ngRPC 是一个高性能、开源和通用的 RPC 框架，面向移动和 HTTP/2 设计，带来诸如双向流、流控、头部压缩、单 TCP 连接上的多复用请求等特。这些特性使得其在移动设备上表现更好，更省电和节省空间占用。\n\n在 gRPC 里客户端应用可以像调用本地对象一样直接调用另一台不同的机器上服务端应用的方法，使得您能够更容易地创建分布式应用和服务。\n\ngRPC 默认使用 protocol buffers，这是 Google 开源的一套成熟的结构数据序列化机制，它的作用与 XML、json 类似，但它是二进制格式，性能好、效率高（缺点：可读性差）。\n\n## 环境配置\n\n### 1.安装 protobuf\n\n下载地址： https://github.com/protocolbuffers/protobuf/releases\n\n检查安装：\n\n```shell\n$ protoc --version                                                                                                                                                                 \nlibprotoc 3.20.0\n```\n\n### 2.安装相关包\n\n安装 golang 的proto编译支持\n```shell\ngo get -u google.golang.org/protobuf\n```\n\n安装 gRPC 包\n```shell\ngo get -u google.golang.org/grpc\n```\n\n## gRPC4种模式\n\ngRPC主要有4种请求和响应模式，分别是简单模式(Simple RPC)、服务端流式（Server-side streaming RPC）、客户端流式（Client-side streaming RPC）、和双向流式（Bidirectional streaming RPC）。\n\n1. 简单模式(Simple RPC)：客户端发起请求并等待服务端响应。\n\n2. 服务端流式（Server-side streaming RPC）：客户端发送请求到服务器，拿到一个流去读取返回的消息序列。 客户端读取返回的流，直到里面没有任何消息。\n\n3. 客户端流式（Client-side streaming RPC）：与服务端数据流模式相反，这次是客户端源源不断的向服务端发送数据流，而在发送结束后，由服务端返回一个响应。\n\n4. 双向流式（Bidirectional streaming RPC）：双方使用读写流去发送一个消息序列，两个流独立操作，双方可以同时发送和同时接收。\n\n## package 以及 go_package\n\npackage用于proto,在引用时起作用;\n\noption go_package用于生成的.pb.go文件,在引用时和生成go包名时起作用\n\n## 其他\n\n1. mustEmbedUnimplementedHelloServiceServer\n\n# 参考\n\n[Bingjian-Zhu / go-grpc-example](https://github.com/Bingjian-Zhu/go-grpc-example)\n\n[grpc tutorial](https://grpc.io/docs/languages/go/basics/)\n\n[指月小筑 grpc](https://www.lixueduan.com/categories/grpc/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmark8s%2Fgo-grpc-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmark8s%2Fgo-grpc-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmark8s%2Fgo-grpc-examples/lists"}