package main
import (
"context"
"fmt"
"google.golang.org/grpc"
"grpccli/services"
"log"
)
func main() {
conn, err := grpc.Dial("localhost:8081", grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
defer conn.Close()
prodClient := services.NewProdServiceClient(conn)//把在服务端生成的protobuf的go文件拷贝到services目录下
prodRes, err := prodClient.GetProdStock(context.Background(), &services.ProdRequest{ProdId: 12})
if err != nil {
log.Fatal(err)
}
fmt.Println(prodRes.ProdStock)
}
原文:https://www.cnblogs.com/hualou/p/12070517.html