客户端
package main import ( "context" "fmt" "log" pb "hello/pb" "github.com/tal-tech/go-zero/core/discov" "github.com/tal-tech/go-zero/zrpc" ) func main() { client := zrpc.MustNewClient(zrpc.RpcClientConf{ Etcd: discov.EtcdConf{ Hosts: []string{"127.0.0.1:2379"}, Key: "hello.rpc", }, }) hello := pb.NewGreeterClient(client.Conn()) reply, err := hello.SayHello(context.Background(), &pb.HelloRequest{Name: "go-zero"}) if err != nil { log.Fatal(err) } fmt.Println(reply.Message) }
运行客户端即可看到输出
hello go-zero