创建客户端并调用
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) }
相关推荐
苦咖啡flask 2020-06-25
mbcsdn 2020-06-05
wanghongsha 2020-04-25
yuanye0 2020-04-18
神龙 2020-02-19
zhujiangtaotaise 2020-01-05
bapinggaitianli 2020-01-01
ltstud 2019-12-19
安之偌素 2019-12-18
Rgenxiao 2011-05-26
xz0mzq 2011-05-26
cxymds 2019-11-04
MrQuinn 2017-08-17
freedomwind00 2018-02-28
瞌睡虫 2015-05-14
davis 2015-05-14
Adolphlwq 2015-05-14