{"id":13740298,"url":"https://github.com/mwitkow/grpc-proxy","last_synced_at":"2025-05-14T10:11:38.670Z","repository":{"id":1778714,"uuid":"44064465","full_name":"mwitkow/grpc-proxy","owner":"mwitkow","description":"gRPC proxy is a Go reverse proxy that allows for rich routing of gRPC calls with minimum overhead.","archived":false,"fork":false,"pushed_at":"2024-06-13T13:04:16.000Z","size":3798,"stargazers_count":957,"open_issues_count":37,"forks_count":209,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-10-29T15:13:09.271Z","etag":null,"topics":["golang","grpc","proxy"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mwitkow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2015-10-11T18:37:50.000Z","updated_at":"2024-10-28T12:43:56.000Z","dependencies_parsed_at":"2024-06-18T11:23:53.669Z","dependency_job_id":null,"html_url":"https://github.com/mwitkow/grpc-proxy","commit_stats":{"total_commits":24,"total_committers":6,"mean_commits":4.0,"dds":"0.20833333333333337","last_synced_commit":"f345521cb9c96262e87206d436a3e508978da70f"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwitkow%2Fgrpc-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwitkow%2Fgrpc-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwitkow%2Fgrpc-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwitkow%2Fgrpc-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mwitkow","download_url":"https://codeload.github.com/mwitkow/grpc-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247968368,"owners_count":21025823,"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":["golang","grpc","proxy"],"created_at":"2024-08-03T04:00:45.971Z","updated_at":"2025-04-09T03:09:43.954Z","avatar_url":"https://github.com/mwitkow.png","language":"Go","funding_links":[],"categories":["\u003ca id=\"01e6651181d405ecdcd92a452989e7e0\"\u003e\u003c/a\u003e工具","Go","Language-Specific"],"sub_categories":["\u003ca id=\"e9f97504fbd14c8bb4154bd0680e9e62\"\u003e\u003c/a\u003e反向代理","Go"],"readme":"# gRPC Proxy\n\n[![Travis Build](https://travis-ci.org/mwitkow/grpc-proxy.svg?branch=master)](https://travis-ci.org/mwitkow/grpc-proxy)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mwitkow/grpc-proxy)](https://goreportcard.com/report/github.com/mwitkow/grpc-proxy)\n[![Go Reference](https://pkg.go.dev/badge/github.com/mwitkow/grpc-proxy.svg)](https://pkg.go.dev/github.com/mwitkow/grpc-proxy)\n[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)\n\n[gRPC Go](https://github.com/grpc/grpc-go) Proxy server\n\n## Project Goal\n\nBuild a transparent reverse proxy for gRPC targets that will make it easy to expose gRPC services\nover the internet. This includes:\n * no needed knowledge of the semantics of requests exchanged in the call (independent rollouts)\n * easy, declarative definition of backends and their mappings to frontends\n * simple round-robin load balancing of inbound requests from a single connection to multiple backends\n\nThe project now exists as a **proof of concept**, with the key piece being the `proxy` package that\nis a generic gRPC reverse proxy handler.\n\n## Proxy Handler\n\nThe package [`proxy`](proxy/) contains a generic gRPC reverse proxy handler that allows a gRPC server to\nnot know about registered handlers or their data types. Please consult the docs, here's an exaple usage.\n\nYou can call `proxy.NewProxy` to create a `*grpc.Server` that proxies requests.\n```go\nproxy := proxy.NewProxy(clientConn)\n``` \n\nMore advanced users will want to define a `StreamDirector` that can make more complex decisions on what\nto do with the request.\n```go\ndirector = func(ctx context.Context, fullMethodName string) (context.Context, *grpc.ClientConn, error) {\n    md, _ := metadata.FromIncomingContext(ctx)\n    outCtx = metadata.NewOutgoingContext(ctx, md.Copy())\n    return outCtx, cc, nil\n\t\n    // Make sure we never forward internal services.\n    if strings.HasPrefix(fullMethodName, \"/com.example.internal.\") {\n        return outCtx, nil, status.Errorf(codes.Unimplemented, \"Unknown method\")\n    }\n    \n    if ok {\n        // Decide on which backend to dial\n        if val, exists := md[\":authority\"]; exists \u0026\u0026 val[0] == \"staging.api.example.com\" {\n            // Make sure we use DialContext so the dialing can be cancelled/time out together with the context.\n            return outCtx, grpc.DialContext(ctx, \"api-service.staging.svc.local\", grpc.WithCodec(proxy.Codec())), nil\n        } else if val, exists := md[\":authority\"]; exists \u0026\u0026 val[0] == \"api.example.com\" {\n            return outCtx, grpc.DialContext(ctx, \"api-service.prod.svc.local\", grpc.WithCodec(proxy.Codec())), nil\n        }\n    }\n    return outCtx, nil, status.Errorf(codes.Unimplemented, \"Unknown method\")\n}\n```\n\nThen you need to register it with a `grpc.Server`. The server may have other handlers that will be served\nlocally.\n\n```go\nserver := grpc.NewServer(\n    grpc.CustomCodec(proxy.Codec()),\n    grpc.UnknownServiceHandler(proxy.TransparentHandler(director)))\npb_test.RegisterTestServiceServer(server, \u0026testImpl{})\n```\n\n## Testing\nTo make debugging a bit simpler, there are some helpers.\n\n`testservice` contains a method `TestTestServiceServerImpl` which performs a complete test against\nthe reference implementation of the `TestServiceServer`.\n\nIn `proxy_test.go`, the test framework spins up a `TestServiceServer` that it tests the proxy \nagainst. To make debugging a bit simpler (eg. if the developer needs to step into \n`google.golang.org/grpc` methods), this `TestServiceServer` can be provided by a server by \npassing `-test-backend=addr` to `go test`. A simple, local-only implementation of \n`TestServiceServer` exists in [`testservice/server`](./testservice/server).\n\n\n## License\n\n`grpc-proxy` is released under the Apache 2.0 license. See [LICENSE.txt](LICENSE.txt).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwitkow%2Fgrpc-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmwitkow%2Fgrpc-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwitkow%2Fgrpc-proxy/lists"}