{"id":21095092,"url":"https://github.com/dan-and-dna/gin-grpc-network","last_synced_at":"2026-05-10T10:21:02.891Z","repository":{"id":63331753,"uuid":"565096899","full_name":"DAN-AND-DNA/gin-grpc-network","owner":"DAN-AND-DNA","description":"A network library that can handle requests for both http and grpc protocols","archived":false,"fork":false,"pushed_at":"2022-11-17T14:45:33.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-07T09:43:24.270Z","etag":null,"topics":["gin","grpc","http","network","protocol"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DAN-AND-DNA.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}},"created_at":"2022-11-12T10:31:22.000Z","updated_at":"2022-11-17T15:22:33.000Z","dependencies_parsed_at":"2022-11-17T05:33:16.843Z","dependency_job_id":null,"html_url":"https://github.com/DAN-AND-DNA/gin-grpc-network","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/DAN-AND-DNA%2Fgin-grpc-network","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAN-AND-DNA%2Fgin-grpc-network/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAN-AND-DNA%2Fgin-grpc-network/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DAN-AND-DNA%2Fgin-grpc-network/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DAN-AND-DNA","download_url":"https://codeload.github.com/DAN-AND-DNA/gin-grpc-network/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243538135,"owners_count":20307104,"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":["gin","grpc","http","network","protocol"],"created_at":"2024-11-19T22:22:27.436Z","updated_at":"2026-05-10T10:21:00.965Z","avatar_url":"https://github.com/DAN-AND-DNA.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-grpc-network\nA network library that can handle both http and grpc requests\n\n## [中文文档](./README_cn.md)\n\n# Example\n[Complete example](https://github.com/DAN-AND-DNA/easyman)\n\n - Write a Handler to handle grpc and http requests:  \n```golang\nfunc setupHandlers() {\n\t// grpc 以pkg service method来区别请求\n\tnetwork.HandleProto(\"webbff\", \"webbff\", \"login\", \u0026webbff.WebBFF_ServiceDesc, gingrpc.Handler{\n\t\tProto: \u0026webbff.LoginReq{},\n\t\tHandleProto: func(ctx context.Context, req interface{}) (interface{}, error) {\n\t\t\tctx, cancel := context.WithTimeout(ctx, 3*time.Second)\n\t\t\tdefer cancel()\n\n\t\t\tl := ctxzap.Extract(ctx)\n\t\t\tmd, ok := metadata.FromIncomingContext(ctx)\n\t\t\tif !ok {\n\t\t\t\treturn nil, status.Error(codes.Internal, \"\")\n\t\t\t}\n\n\t\t\tct := md.Get(\"content-type\")\n\t\t\tif len(ct) == 0 {\n\t\t\t\treturn nil, status.Error(codes.NotFound, \"content-type lost\")\n\t\t\t}\n\n\t\t\tl.Info(\"get Content-Type\", zap.String(\"Content-Type\", ct[0]))\n\n\t\t\treqProto := req.(*webbff.LoginReq)\n\t\t\tusername := reqProto.GetName()\n\t\t\tpassword := reqProto.GetPassword()\n\n\t\t\tl.Info(\"user try to login\", zap.String(\"name\", username), zap.String(\"password\", password))\n\n\t\t\treturn \u0026webbff.LoginResp{Token: \"xxxxxxxx\"}, nil\n\t\t},\n\t})\n}\n```\n\n## http performance\n```c++\ngoos: windows\ngoarch: amd64\npkg: github.com/dan-and-dna/gin-grpc\ncpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz\nBenchmarkGinGrpc\nBenchmarkGinGrpc-12      3528080              1675 ns/op            1496 B/op           13 allocs/op\nPASS\n```\n \n## grpc performance\nThe middleware is used, so there is no additional overhead, just grpc-go\n```c++\ngoos: windows\ngoarch: amd64\npkg: easyman\ncpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz\nBenchmarkGrpc\nBenchmarkGrpc-12          112734             10224 ns/op            1702 B/op           36 allocs/op\nPASS\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdan-and-dna%2Fgin-grpc-network","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdan-and-dna%2Fgin-grpc-network","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdan-and-dna%2Fgin-grpc-network/lists"}