{"id":20524112,"url":"https://github.com/kimi0230/practise-grpc-go","last_synced_at":"2026-05-08T15:52:27.116Z","repository":{"id":105027019,"uuid":"365476775","full_name":"kimi0230/practise-gRPC-go","owner":"kimi0230","description":"Practise gRPC  base on https://github.com/simplesteph/grpc-go-course","archived":false,"fork":false,"pushed_at":"2023-01-12T12:32:33.000Z","size":105,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T10:55:19.643Z","etag":null,"topics":["go","golang","grpc","grpc-go","mongo-go-driver","mongodb","rpc"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kimi0230.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-08T09:46:31.000Z","updated_at":"2024-06-21T02:03:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9fc616a-63a5-4474-8ee8-2dd18030b736","html_url":"https://github.com/kimi0230/practise-gRPC-go","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/kimi0230%2Fpractise-gRPC-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimi0230%2Fpractise-gRPC-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimi0230%2Fpractise-gRPC-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimi0230%2Fpractise-gRPC-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kimi0230","download_url":"https://codeload.github.com/kimi0230/practise-gRPC-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242128325,"owners_count":20076177,"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":["go","golang","grpc","grpc-go","mongo-go-driver","mongodb","rpc"],"created_at":"2024-11-15T22:47:55.651Z","updated_at":"2026-05-08T15:52:22.087Z","avatar_url":"https://github.com/kimi0230.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Practise gRPC Golang \n\nPractise gRPC base on [simplesteph/grpc-go-course][grpc-go-course].\n\n# Content\n\n- PubSub [moby/pkg/pubsub](https://github.com/moby/moby/blob/master/pkg/pubsub/publisher.go)\n- Greeting Service\n- Calculator Service\n- Unary, Server Streaming, Client Streaming, BiDi Streaming\n- Error Handling, Deadlines, SSL Encryption\n- Blog API CRUD w/ MongoDB\n- metadata (header)\n\n# Installation\n\n### MAC\n``` shell\n# protobuf\nbrew install protobuf\ngo get -u google.golang.org/grpc\ngo get -u github.com/golang/protobuf/protoc-gen-go\n\n# Use it to generate faster marshaling and unmarshaling go code for your protocol buffers.\ngo get -u github.com/gogo/protobuf/protoc-gen-gofast\n\n# MongoDB Go Driver\ngo get -u go.mongodb.org/mongo-driver/mongo\ngo get -u gopkg.in/mgo.v2/bson\n\n# docker pub/sub\ngo get -u github.com/moby/moby/pkg/pubsub\n```\n\n### [evans]\n##### installation\nEvans has been created to use easier than other existing gRPC clients.\n``` shell\nbrew tap ktr0731/evans\nbrew install evans\n```\n\n##### usage\n``` shell\n# connect to gRPC server\nevans -p 50051 -r\n\n# commands\nshow package\nshow service\ncall Sum\n```\n\n### MongoDB\n#### 1. Offical Install Package\n##### download\nhttps://www.mongodb.com/try/download/community\n\n##### [installation][mongodb-osx-install]\nmv file to /usr/local and change name\n``` shell\ncd /usr/local\nmv ~/mongodb-macos-x86_64-4.4.6/ mongodb\n```\n\nadd bin to path\n``` shell\nvi ~/.zshrc\n# add PATH\nexport PATH=/usr/local/mongodb/bin:$PATH\nsource ~/.zshrc\n```\n\ncreate data, log folder\n``` shell\n# create data, log folder\nsudo mkdir -p /usr/local/var/mongodb\nsudo mkdir -p /usr/local/var/log/mongodb\n\n# make sure folder permission\nsudo chown kimiimac /usr/local/var/mongodb\nsudo chown kimiimac /usr/local/var/log/mongodb\n```\n\nstart MongoDB\n``` shell\nmongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork\n```\n\n#### 2. Brew Install\n```\n# install\nbrew tap mongodb/brew\nsudo chown -R $(whoami) /usr/local/var/log\nchmod u+w /usr/local/var/log\nbrew install mongodb-community\n\n# brew start\nbrew services start mongodb-community\n\n# start MongoDB\nmongod --config /usr/local/etc/mongod.conf --fork\n```\n\n# Generate protobuf\n### greet\n``` shell\nmake build_greet\n```\n\n### calculator\n``` shell\nmake build_calculator\n```\n\n### blog\n``` shell\nmake build_blog\n```\n\n### gpubsub\n``` shell\nmake build_gpubsub\n```\n\n# SSL\n### generate SSL Key\n``` shell\ncd ssl\n./instructions.sh  \n```\n\n### code sample\n* [gRPC Authentication][auth]\n#### 1. Base case - no encryption or authentication\n##### Client:\n```go\nconn, _ := grpc.Dial(\"localhost:50051\", grpc.WithInsecure())\n// error handling omitted\nclient := pb.NewGreeterClient(conn)\n// ...\n```\n\n##### Server:\n``` go\ns := grpc.NewServer()\nlis, _ := net.Listen(\"tcp\", \"localhost:50051\")\n// error handling omitted\ns.Serve(lis)\n```\n\n#### 2. With server authentication SSL/TLS\n##### Client:\n``` go\ncreds, _ := credentials.NewClientTLSFromFile(certFile, \"\")\nconn, _ := grpc.Dial(\"localhost:50051\", grpc.WithTransportCredentials(creds))\n// error handling omitted\nclient := pb.NewGreeterClient(conn)\n// ...\n```\n\n##### Server:\n``` go\ncreds, _ := credentials.NewServerTLSFromFile(certFile, keyFile)\ns := grpc.NewServer(grpc.Creds(creds))\nlis, _ := net.Listen(\"tcp\", \"localhost:50051\")\n// error handling omitted\ns.Serve(lis)\n```\n\n#### 3. Authenticate with Google\n``` go\npool, _ := x509.SystemCertPool()\n// error handling omitted\ncreds := credentials.NewClientTLSFromCert(pool, \"\")\nperRPC, _ := oauth.NewServiceAccountFromFile(\"service-account.json\", scope)\nconn, _ := grpc.Dial(\n    \"greeter.googleapis.com\",\n    grpc.WithTransportCredentials(creds),\n    grpc.WithPerRPCCredentials(perRPC),\n)\n// error handling omitted\nclient := pb.NewGreeterClient(conn)\n// ...\n```\n\n# Demo\n### greet\n```shell\ngo run greet/greet_server/server.go\ngo run greet/greet_client/client.go\n```\n\n### calculator\n```shell\ngo run calculator/calculator_server/server.go\ngo run calculator/calculator_client/client.go\n```\n\n### blog\n```shell\ngo run blog/blog_server/server.go\ngo run blog/blog_client/client.go\n```\n\n### gpubsub\n```shell\ngo run gpubsub/gpubsub_server/server.go\n# subscriber\ngo run gpubsub/gpubsub_client_sub/client.go\n# publisher\ngo run gpubsub/gpubsub_client_pub/client.go\n```\n\n# Reference\n* https://developers.google.com/protocol-buffers/docs/gotutorial\n* https://github.com/simplesteph/grpc-go-course\n* https://github.com/gogo/protobuf\n* https://grpc.io/docs/guides/auth/\n* https://github.com/ktr0731/evans\n* https://github.com/mongodb/mongo-go-driver\n* https://grpc.io/\n* https://jbrandhorst.com/post/gogoproto/\n* https://github.com/gogo/grpc-example\n* https://jbrandhorst.com/post/gogoproto/\n* https://www.itread01.com/content/1587524882.html\n* [Robust gRPC communication on Google Cloud Run (but not only!)](https://threedots.tech/post/robust-grpc-google-cloud-run/?utm_source=convertkit\u0026utm_medium=email\u0026utm_campaign=Robust+GRPC+Communication+In+Google+Cloud+Run%20-%204041200)\n\n## Notes\n數字1,2,3,4\n是用來代表編號、唯一識別碼，好讓程式識別這個變數，因為到時大家都被壓縮成二進制 認不出誰是誰，有編號要認人比較方便。\n在同一個message裡面識別碼不可重複，但不同message之間重複就沒關係了\n\n```proto\nmessage Blog {\n  string id = 1;\n  string author_id = 2;\n  string title = 3;\n  string content = 4;\n}\n```\n\n# TODO\n - [ ] [middleware](https://github.com/grpc-ecosystem/go-grpc-middleware)\n\n\u003c!-- https://www.markdownguide.org/basic-syntax/ --\u003e\n[gotutorial]: https://developers.google.com/protocol-buffers/docs/gotutorial\n[grpc-go-course]: https://github.com/simplesteph/grpc-go-course\n[protobuf]: https://github.com/gogo/protobuf\n[auth]: https://grpc.io/docs/guides/auth/\n[evans]: https://github.com/ktr0731/evans\n[mongodb-osx-install]: https://www.runoob.com/mongodb/mongodb-osx-install.html\n[MongoDB Go Driver]: https://github.com/mongodb/mongo-go-driver\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimi0230%2Fpractise-grpc-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimi0230%2Fpractise-grpc-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimi0230%2Fpractise-grpc-go/lists"}