golang grpc动态客户端

golang grpc动态客户端,go,grpc,Go,Grpc,坚持使用动态客户端 我只需要确保grpc在健康端点上没有错误地响应,到目前为止,我能够获取服务 package main import ( "context" "crypto/tls" "time" "github.com/davecgh/go-spew/spew" "github.com/jhump/protoreflect/grpcreflect"

坚持使用动态客户端 我只需要确保grpc在健康端点上没有错误地响应,到目前为止,我能够获取服务

package main

import (
    "context"
    "crypto/tls"
    "time"

    "github.com/davecgh/go-spew/spew"
    "github.com/jhump/protoreflect/grpcreflect"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials"
    reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
)

func main() {
    creds := credentials.NewTLS(&tls.Config{InsecureSkipVerify: false})
    opts := []grpc.DialOption{
        grpc.WithTransportCredentials(creds),
    }
    ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
    defer cancel()
    conn, err := grpc.DialContext(context.TODO(), "endpoint:443", opts...)
    if err != nil {
        panic(err)
    }
    refClient := grpcreflect.NewClient(ctx, reflectpb.NewServerReflectionClient(conn))
    spew.Dump(refClient.ListServices())
    spew.Dump(refClient.ResolveService("grpc.health.v1.Health"))
}

调用
grpc.DialContext()
是否失败?如果是,返回什么错误?此外,您还可以打开日志记录并查看发生了什么:
GRPC\u GO\u LOG\u SEVERITY\u LEVEL=info GRPC\u GO\u LOG\u VERBOSITY\u LEVEL=99