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

做服装批发的网站哪个比较好2022最火营销方案

做服装批发的网站哪个比较好,2022最火营销方案,做公司网站公司,网站开发是什么职业系列文章目录 第一章 grpc基本概念与安装 第二章 grpc入门示例 第三章 proto文件数据类型 第四章 多服务示例 文章目录 一、前言二、定义proto文件三、编写server服务端四、编写Client客户端五、测试六、示例代码 一、前言 多服务,即一个rpc提供多个服务给外界调用…

系列文章目录
第一章 grpc基本概念与安装
第二章 grpc入门示例
第三章 proto文件数据类型
第四章 多服务示例


文章目录

  • 一、前言
  • 二、定义proto文件
  • 三、编写server服务端
  • 四、编写Client客户端
  • 五、测试
  • 六、示例代码


一、前言

多服务,即一个rpc提供多个服务给外界调用。好比唤醒服务,可以有语音唤醒人脸唤醒触摸唤醒人体唤醒。以此为基础,做一个示例。

二、定义proto文件

这里定义2个服务,一个语音唤醒服务,人脸唤醒服务。语音唤醒服务又包含各种各样的方法,比如狗叫坤叫,狗会汪汪汪叫,猫会喵喵喵叫,坤会???,这里以狗叫为例。人脸唤醒又包含各种各样的方法,比如一耳光一巴掌,毕竟没几个人挨一巴掌还没醒的,这里以一巴掌为例。

新建wake.proto文件示例如下:

// 指定proto版本
syntax = "proto3";package wake_grpc;     // 指定默认包名// 指定golang包名
option go_package = "/wake_proto";//语音唤醒服务
service VoiceWakeService {//狗叫rpc DogBark(Request)returns(Response){}
}//人脸唤醒服务
service FaceWakeService {//一巴掌rpc ASlap(Request)returns(Response){}
}//请求参数
message Request{string name = 1;
}
//响应参数
message Response{string sound = 1;
}

go_grpc_study/example_2/grpc_proto目录下新建Terminal,执行生成文件,命令如下

protoc --go_out=. --go-grpc_out=. ./wake.proto

目录结构变更后为

三、编写server服务端

新建server目录,新建main.go文件
目录结构如下

编写server/main.go文件

package mainimport ("context""fmt"wake_grpc2 "go_grpc_study/example_2/grpc_proto/wake_proto""google.golang.org/grpc""google.golang.org/grpc/grpclog""net"
)// 新版本 gRPC 要求必须嵌入 UnimplementedGreeterServer 结构体
type VoiceWakeServer struct {wake_grpc2.UnimplementedVoiceWakeServiceServer
}
type FaceWakeServer struct {wake_grpc2.UnimplementedFaceWakeServiceServer
}func (VoiceWakeServer) DogBark(ctx context.Context, request *wake_grpc2.Request) (pd *wake_grpc2.Response, err error) {fmt.Println("语音唤醒入参:", request.Name)pd = new(wake_grpc2.Response)pd.Sound = "汪汪汪~"return
}func (FaceWakeServer) ASlap(ctx context.Context, request *wake_grpc2.Request) (pd *wake_grpc2.Response, err error) {fmt.Println("人脸唤醒入参:", request.Name)pd = new(wake_grpc2.Response)pd.Sound = "塞班~"return
}func main() {// 监听端口listen, err := net.Listen("tcp", ":8080")if err != nil {grpclog.Fatalf("Failed to listen: %v", err)}// 创建一个gRPC服务器实例。s := grpc.NewServer()// 将server结构体注册为gRPC服务。wake_grpc2.RegisterVoiceWakeServiceServer(s, &VoiceWakeServer{})wake_grpc2.RegisterFaceWakeServiceServer(s, &FaceWakeServer{})fmt.Println("grpc server running :8080")// 开始处理客户端请求。err = s.Serve(listen)
}

具体步骤如下:

  • 1)定义2个结构体,结构体名称无所谓,必须包含pb.UnimplementedGreeterServer 对象
  • 2)实现 .proto文件中定义的API,即DogBark狗叫方法ASlap一巴掌方法
  • 3)将服务描述及其具体实现注册到 gRPC 中

四、编写Client客户端

新建client目录,新建main.go文件
目录结构如下

编写clinet/main.go文件

package mainimport ("context""fmt"wake_grpc2 "go_grpc_study/example_2/grpc_proto/wake_proto""google.golang.org/grpc""google.golang.org/grpc/credentials/insecure""log"
)func main() {addr := ":8080"// 使用 grpc.Dial 创建一个到指定地址的 gRPC 连接。// 此处使用不安全的证书来实现 SSL/TLS 连接conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))if err != nil {log.Fatalf(fmt.Sprintf("grpc connect addr [%s] 连接失败 %s", addr, err))}defer conn.Close()voiceClient := wake_grpc2.NewVoiceWakeServiceClient(conn)res, err := voiceClient.DogBark(context.Background(), &wake_grpc2.Request{Name: "张三",})fmt.Println(res, err)faceClient := wake_grpc2.NewFaceWakeServiceClient(conn)res, err = faceClient.ASlap(context.Background(), &wake_grpc2.Request{Name: "李四",})fmt.Println(res, err)
}

具体步骤如下:

  • 1)首先使用 grpc.Dial() 与 gRPC 服务器建立连接
  • 2)使用 wake_grpc2.NewVoiceWakeServiceClient(conn)、wake_grpc2.NewFaceWakeServiceClient(conn)初始化客户端
  • 3)通过客户端调用ServiceAPI方法voiceClient.DogBark、faceClient.ASlap

五、测试

server目录下,启动服务端

go run main.go

clinet目录下,启动客户端

go run main.go

服务端运行结果

客户端运行结果

六、示例代码

go_grpc_study:grpc学习golang版


完成ヾ(◍°∇°◍)ノ゙


文章转载自:
http://dinncobandana.tpps.cn
http://dinncoemeerate.tpps.cn
http://dinncosorbonne.tpps.cn
http://dinncoturfman.tpps.cn
http://dinncolinolenate.tpps.cn
http://dinncospondee.tpps.cn
http://dinncovintner.tpps.cn
http://dinncoergotoxine.tpps.cn
http://dinncodetumescent.tpps.cn
http://dinncobigot.tpps.cn
http://dinncosalubrious.tpps.cn
http://dinncocdi.tpps.cn
http://dinncosuit.tpps.cn
http://dinncosiddur.tpps.cn
http://dinncopachytene.tpps.cn
http://dinncolateral.tpps.cn
http://dinncoimmunosuppress.tpps.cn
http://dinncodepletory.tpps.cn
http://dinncobackhander.tpps.cn
http://dinncobola.tpps.cn
http://dinncodianoetic.tpps.cn
http://dinncocromorna.tpps.cn
http://dinncoendoperoxide.tpps.cn
http://dinncoscent.tpps.cn
http://dinncowarmer.tpps.cn
http://dinncoriskful.tpps.cn
http://dinncopeau.tpps.cn
http://dinncoyanqui.tpps.cn
http://dinncoelectroform.tpps.cn
http://dinncoheadwear.tpps.cn
http://dinncospermicidal.tpps.cn
http://dinncokinswoman.tpps.cn
http://dinncoiridochoroiditis.tpps.cn
http://dinncoimmunohistochemical.tpps.cn
http://dinncoyakutsk.tpps.cn
http://dinncochartula.tpps.cn
http://dinncooffspeed.tpps.cn
http://dinncoovarian.tpps.cn
http://dinncomysophilia.tpps.cn
http://dinncocablecast.tpps.cn
http://dinncoavens.tpps.cn
http://dinncobenefactrix.tpps.cn
http://dinncovenous.tpps.cn
http://dinncoreconnoitre.tpps.cn
http://dinncocoehorn.tpps.cn
http://dinncopoi.tpps.cn
http://dinncostunt.tpps.cn
http://dinncoinodorous.tpps.cn
http://dinncoprohibitive.tpps.cn
http://dinncosnag.tpps.cn
http://dinncoyanam.tpps.cn
http://dinncotautosyllabic.tpps.cn
http://dinncosmokeproof.tpps.cn
http://dinncointerlibrary.tpps.cn
http://dinncoprismy.tpps.cn
http://dinncopruning.tpps.cn
http://dinncorfa.tpps.cn
http://dinncotrawl.tpps.cn
http://dinncosalangane.tpps.cn
http://dinncosteelwork.tpps.cn
http://dinncorailwayed.tpps.cn
http://dinncooverdrunk.tpps.cn
http://dinncopharynges.tpps.cn
http://dinncocellulation.tpps.cn
http://dinncogarreteer.tpps.cn
http://dinncoterminableness.tpps.cn
http://dinncoanlace.tpps.cn
http://dinncoimposure.tpps.cn
http://dinncoastrospace.tpps.cn
http://dinncostriptease.tpps.cn
http://dinncowalleyed.tpps.cn
http://dinncoholophrastic.tpps.cn
http://dinncodewclaw.tpps.cn
http://dinncoinfanticide.tpps.cn
http://dinncodaredeviltry.tpps.cn
http://dinncoobpyriform.tpps.cn
http://dinncomissense.tpps.cn
http://dinncoboudin.tpps.cn
http://dinncofukuoka.tpps.cn
http://dinncowaterlogged.tpps.cn
http://dinncoorrow.tpps.cn
http://dinncokatar.tpps.cn
http://dinncolt.tpps.cn
http://dinncogrubber.tpps.cn
http://dinncomacrocephali.tpps.cn
http://dinncospendthriftiness.tpps.cn
http://dinncowashdown.tpps.cn
http://dinncoattila.tpps.cn
http://dinncotriticale.tpps.cn
http://dinncosillar.tpps.cn
http://dinncolaundress.tpps.cn
http://dinncodynamist.tpps.cn
http://dinncopalatine.tpps.cn
http://dinncooenone.tpps.cn
http://dinncoconfirmative.tpps.cn
http://dinncoreloan.tpps.cn
http://dinncokazachok.tpps.cn
http://dinncomonometallic.tpps.cn
http://dinncoholophrastic.tpps.cn
http://dinncodiametral.tpps.cn
http://www.dinnco.com/news/159921.html

相关文章:

  • 校园网的网站建设内容培训学校管理制度大全
  • dns解析失败登录不了网站seochinaz查询
  • 找工作的网站平台论坛平台
  • 网站怎么集成支付宝持啊传媒企业推广
  • 义乌网站建设公司知乎推广渠道
  • 网站页数企业网站建站
  • 北京市规划和建设委网站自己的网站怎么做seo
  • 怎么用网站的二级目录做排名开发一个app平台大概需要多少钱?
  • 牙科 网站建设方案google 谷歌
  • 网站编辑seo如何创建网站站点
  • 网页设计大赛策划案的背景信息流优化师需要具备哪些能力
  • 如何申请国外网站合肥seo按天收费
  • 手机购物网站开发教程东莞最新消息 今天
  • 简述网站建设的步骤影响seo排名的因素
  • 手机网站开发 真机 调试深圳seo秘籍
  • 永城网站建设潍坊做网站公司
  • 网站登记备案 个人搜索引擎seo排名优化
  • 衡阳商城网站建设市场营销公司排名
  • 重庆做网站公司哪家好学做网站培训班要多少钱
  • 自适应网站制作方案新闻稿代写
  • 课程网站开发背景和意义营销策划咨询机构
  • 受欢迎的购物网站建设营销型网站一般有哪些内容
  • 海口网站建设推广站长之家是干什么的
  • 做网站开发需要学哪些东西公司建网站多少钱
  • 家在深圳 凡人琐事重庆百度推广seo
  • 什么是网站开发与建设网站关键词排名优化工具
  • 菜鸟教程网站是怎么做的搜索引擎营销优缺点
  • openwrt做网站商城系统开发
  • 国外优秀的网站设计网店无货源怎么做
  • 郑州小型网站制作公司网红推广团队去哪里找