{"id":26897485,"url":"https://github.com/chara-x/grpc","last_synced_at":"2025-04-01T04:42:38.160Z","repository":{"id":243962529,"uuid":"797907740","full_name":"Chara-X/grpc","owner":"Chara-X","description":"Grpc client and server base on json","archived":false,"fork":false,"pushed_at":"2025-03-27T20:11:43.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T21:25:17.522Z","etag":null,"topics":["client","grpc","json","server"],"latest_commit_sha":null,"homepage":"","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/Chara-X.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-08T18:05:03.000Z","updated_at":"2025-03-27T20:11:48.000Z","dependencies_parsed_at":"2025-03-27T21:22:34.744Z","dependency_job_id":"612e1b4a-9076-4d83-8a4f-6db64a438d04","html_url":"https://github.com/Chara-X/grpc","commit_stats":null,"previous_names":["chara-x/grpc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chara-X%2Fgrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chara-X%2Fgrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chara-X%2Fgrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chara-X%2Fgrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chara-X","download_url":"https://codeload.github.com/Chara-X/grpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246586069,"owners_count":20801026,"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":["client","grpc","json","server"],"created_at":"2025-04-01T04:42:37.584Z","updated_at":"2025-04-01T04:42:38.146Z","avatar_url":"https://github.com/Chara-X.png","language":"Go","readme":"# grpc\n\n## Client\n\n```go\nfunc main() {\n\tvar caCert, _ = os.ReadFile(\"resources/cert.pem\")\n\tvar caCertPool = x509.NewCertPool()\n\tcaCertPool.AppendCertsFromPEM(caCert)\n\tvar cli = \u0026http.Client{Transport: \u0026http2.Transport{TLSClientConfig: \u0026tls.Config{RootCAs: caCertPool}}}\n\tUnary(cli)\n\t// ClientStreaming(cli)\n\t// ServerStreaming(cli)\n\t// DuplexStreaming(cli)\n}\nfunc Unary(cli *http.Client) {\n\tvar _, _, _, resBody = grpc.StreamingCall(cli, \"https://127.0.0.1:2333/User/GetOne\", http.Header{}, user.GetOneRequest{Id: 2})\n\tdefer resBody.Close()\n\tvar u *user.User\n\tresBody.Decode(\u0026u)\n\tfmt.Println(u)\n}\nfunc ClientStreaming(cli *http.Client) {\n\tvar _, reqBody, res, resBody = grpc.StreamingCall(cli, \"https://127.0.0.1:2333/User/Count\", http.Header{}, nil)\n\tgo func() {\n\t\tfor i := 1; i \u003c 5; i++ {\n\t\t\treqBody.Encode(\u0026user.User{Id: int32(i), Name: \"Chara-X\"})\n\t\t\ttime.Sleep(time.Second)\n\t\t}\n\t\treqBody.Close()\n\t}()\n\tdefer resBody.Close()\n\tvar count *user.CountResponse\n\tif resBody.Decode(\u0026count) != nil {\n\t\tfmt.Println(res.Trailer[grpc.GrpcStatus])\n\t}\n\tfmt.Println(count)\n}\nfunc ServerStreaming(cli *http.Client) {\n\tvar _, _, res, resBody = grpc.StreamingCall(cli, \"https://127.0.0.1:2333/User/GetAll\", map[string][]string{}, basic.Nil{})\n\tdefer resBody.Close()\n\tfor {\n\t\tvar u *user.User\n\t\tif resBody.Decode(\u0026u) != nil {\n\t\t\tfmt.Println(res.Trailer[grpc.GrpcStatus])\n\t\t\tbreak\n\t\t}\n\t\tfmt.Println(u)\n\t}\n}\nfunc DuplexStreaming(cli *http.Client) {\n\tvar _, reqBody, res, resBody = grpc.StreamingCall(cli, \"https://127.0.0.1:2333/User/Filter\", map[string][]string{}, nil)\n\tgo func() {\n\t\tfor i := 1; i \u003c 5; i++ {\n\t\t\treqBody.Encode(\u0026user.User{Id: int32(i), Name: \"Chara-X\"})\n\t\t\ttime.Sleep(time.Second)\n\t\t}\n\t\treqBody.Close()\n\t}()\n\tdefer resBody.Close()\n\tfor {\n\t\tvar u *user.User\n\t\tif err := resBody.Decode(\u0026u); err != nil {\n\t\t\tfmt.Println(res.Trailer[grpc.GrpcStatus])\n\t\t\tbreak\n\t\t}\n\t\tfmt.Println(u)\n\t}\n}\n```\n\n## Server\n\n```go\nfunc Streaming(res http.ResponseWriter, req *http.Request) {\n\tvar resBody, reqBody = grpc.NewEncoder(res), grpc.NewDecoder(req.Body)\n\tgrpc.WriteHeader(res, http.StatusOK)\n\tfor {\n\t\tvar req *user.User\n\t\tif err := reqBody.Decode(\u0026req); err != nil {\n\t\t\tbreak\n\t\t}\n\t\tif req.Id == 2 {\n\t\t\tres.Header().Set(grpc.GrpcMessage, \"Bad Request\")\n\t\t\tres.Header().Set(grpc.GrpcStatus, \"400\")\n\t\t\tbreak\n\t\t}\n\t\tresBody.Encode(req)\n\t}\n}\n```\n\n## Reference\n\n[HTTP2 client-server full-duplex connection](https://github.com/posener/h2conn)\n\n[HTTP/2 Adventure in the Go World](https://posener.github.io/http2)\n\n[Using gRPC with JSON](https://jbrandhorst.com/post/grpc-json)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchara-x%2Fgrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchara-x%2Fgrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchara-x%2Fgrpc/lists"}