当前位置: 首页 > news >正文

网站建设沧州中国企业网信息查询

网站建设沧州,中国企业网信息查询,爱站挖词,推广营销外包准备工作 Go, 最新版的 如果不会安装看Getting Started. Protocol buffer compiler, protoc, version 3. 想要安装, 请读Protocol Buffer Compiler Installation. 为 protocol compiler安装Go plugins: 想要安装运行以下命令: $ go install google.golang.org/protobuf/cmd/…准备工作 Go, 最新版的 如果不会安装看Getting Started. Protocol buffer compiler, protoc, version 3. 想要安装, 请读Protocol Buffer Compiler Installation.  为 protocol compiler安装Go plugins: 想要安装运行以下命令: $ go install google.golang.org/protobuf/cmd/protoc-gen-gov1.28 $ go install google.golang.org/grpc/cmd/protoc-gen-go-grpcv1.2更新环境变量好让protocol 可以直接调用: $ export PATH$PATH:$(go env GOPATH)/bin 记得保存. 获取例子代码 这些代码是 grpc-go 仓库的一部分. Download the repo as a zip file and unzip it,或者直接clone它: $ git clone -b v1.58.0 --depth 1 https://github.com/grpc/grpc-go进入quick start example 目录: $ cd grpc-go/examples/helloworld 运行范例 从 examples/helloworld 目录: 1.编译并执行服务端代码: $ go run greeter_server/main.go再开一个终端编译并运行客户端代码 output: $ go run greeter_client/main.go Greeting: Hello world恭喜! 你刚才成功地运行了client-server grpc应用 更新刚才的gRPC服务 接下来你将更新这个应用使用一个额外的服务方法。grpc服务使用protocol buffers.想要学习更多关于怎样在.proto文件中定义一个服务请看 Basics tutorial. 现在,你只需要知道server端和客户端使用一个SayHello() RPC方法使得客户端获取到了服务端的方法返回的响应方法定义像是 // The greeting service definition. service Greeter {// Sends a greetingrpc SayHello (HelloRequest) returns (HelloReply) {} }// The request message containing the users name. message HelloRequest {string name 1; }// The response message containing the greetings message HelloReply {string message 1; }打开helloworld/helloworld.proto 然后 添加一个新的SayHelloAgain() 方法, 使用相同的请求和相应类型: // The greeting service definition. service Greeter {// Sends a greetingrpc SayHello (HelloRequest) returns (HelloReply) {}// Sends another greetingrpc SayHelloAgain (HelloRequest) returns (HelloReply) {} }// The request message containing the users name. message HelloRequest {string name 1; }// The response message containing the greetings message HelloReply {string message 1; }记得保存 重新生成 gRPC 代码 在你能用新的服务端方法前, 你得先重新生成 .proto file. 因为仍旧处在 examples/helloworld 目录, 运行接下来的命令: $ protoc --go_out. --go_optpathssource_relative \--go-grpc_out. --go-grpc_optpathssource_relative \helloworld/helloworld.proto这将重新生成helloworld/helloworld.pb.go 和 helloworld/helloworld_grpc.pb.go files, 其中包含: Code for populating, serializing, and retrieving HelloRequest and HelloReply message types.Generated client and server code. 更新并运行程序 你已经生成了server和cilent代码但你人就需要实现你手写的那些方法 更新服务端 打开 greeter_server/main.go 然后增加如下所示的函数: func (s *server) SayHelloAgain(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {return pb.HelloReply{Message: Hello again in.GetName()}, nil }更新客户端 打开 greeter_client/main.go 并在 main()函数的最底部增加如下代码: r, err c.SayHelloAgain(ctx, pb.HelloRequest{Name: *name}) if err ! nil {log.Fatalf(could not greet: %v, err) } log.Printf(Greeting: %s, r.GetMessage())记得保存. 运行! 运行你之前写好的程序.在examples/helloworld directory下运行下面的命令 运行 server: $ go run greeter_server/main.go运行另一个终端以下命令这次我们增加了一个参数: $ go run greeter_client/main.go --nameAlice你会看到如下的输出: Greeting: Hello Alice Greeting: Hello again Alice接下来 Learn how gRPC works in Introduction to gRPC and Core concepts.Work through the Basics tutorial.Explore the API reference.
http://www.dnsts.com.cn/news/43824.html

相关文章:

  • 网站宣传方案广东东莞直播基地
  • 做系统用哪个网站好安康升降平台
  • 电销做网站项目鸿蒙系统软件开发教程
  • 网站开发需要什么专业知识nodejs网站开发教程
  • 如何向百度提交网站海会主机
  • 衡阳城乡建设局网站wordpress弹框登陆
  • 屏蔽网站接口js广告wordpress文字模板下载
  • 网站建设嘉兴公司电话公司网上注册
  • 电子商务网站开发计划书招c1驾驶员300元一天
  • 网站建设与维护教学计划公司图标设计大全免费 logo
  • 深圳网站建设如何制作域名iis网站添加
  • 石大远程网页设计及网站建设答案二级域名的网站备案
  • 重庆网站设计生产厂家建立网站需要钱吗
  • 网站建设需要多少深圳易捷网站建设
  • 网站建设中端口号的作用是什么意思用什么语言能写网站吗
  • 32套网站后台管理系统模板北京服务器租用
  • 广州做网站最好的公司成都网站设计排名的公司价格
  • 下载官方网站app下载农商1号的网站建设费
  • 网络公共关系seo技术员
  • 长沙网站排名推广百度网网站建设的目标
  • 中国设计师联盟网站asp购物网站源码
  • 东莞网络建站公司网站设计网络推广
  • 优化网站关键词哈尔滨建设工程招标网
  • 贵阳有哪些可以制作网站的公司吗企业信用信息公示官网
  • 长沙做网站的公司对比如何规划企业网络推广方案
  • 百度网站推广咨询网站设计流程是
  • 苏州企业如何建网站网站开发实验总结
  • 做网站大图片中国郴州
  • 大学网站策划方案各国网站的域名
  • 公司网站建设开发wordpress下载主题模板