proxy: use grpc interfaces instead of *grpc.Server and *grpc.ClientConn, use Service and service Options

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
2025-04-14 08:56:55 +02:00
parent 82e4d9a944
commit 8999dedd32
7 changed files with 182 additions and 230 deletions

View File

@ -14,26 +14,27 @@ import (
"google.golang.org/grpc/status"
"go.linka.cloud/grpc-toolkit/proxy"
"go.linka.cloud/grpc-toolkit/service"
)
var (
director proxy.StreamDirector
)
func ExampleNewProxy() {
func ExampleNew() {
dst, err := grpc.Dial("example.com")
if err != nil {
log.Fatalf("dialing example.org: %v", err)
}
proxy := proxy.NewProxy(dst)
proxy, _ := proxy.New(dst)
_ = proxy
}
func ExampleRegisterService() {
// A gRPC server with the proxying codec enabled.
server := grpc.NewServer()
// A gRPC service with the proxying codec enabled.
svc, _ := service.New()
// Register a TestService with 4 of its methods explicitly.
proxy.RegisterService(server, director,
proxy.RegisterService(svc, director,
"mwitkow.testproto.TestService",
"PingEmpty", "Ping", "PingError", "PingList")
}