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

网站举报有奖平台互联网推广员是做什么的

网站举报有奖平台,互联网推广员是做什么的,做网站的基础架构,采购员从那个网站开发供应商option自定义http规则和http body响应 简介 本篇接上文 golang 工程组件:grpc-gateway 环境安装默认网关测试 默认网关配置终究是难用,本篇介绍一下proto里采用option自定义http规则以及让网关返回http响应而不是我们定义的grpc响应 option定义http…

option自定义http规则和http body响应

简介

本篇接上文

golang 工程组件:grpc-gateway 环境安装+默认网关测试

默认网关配置终究是难用,本篇介绍一下proto里采用option自定义http规则以及让网关返回http响应而不是我们定义的grpc响应

option定义http规则和httpbody响应

引入库。可以直接拷贝grpc-gateway源码下google文件夹到项目下

import "google/api/annotations.proto";
import "google/api/httpbody.proto";
import "google/protobuf/empty.proto";

user.proto

syntax = "proto3";
package  echo;
option go_package = "echo/proto";import "google/api/annotations.proto";
import "google/api/httpbody.proto";
import "google/protobuf/empty.proto";message User{int64 id = 1;// 改成下划线形式string userName = 2[json_name="user_name"];int32 age = 3;string phone = 4;Addr addr = 5;
}message Addr {string province = 1;string city = 2;string county = 3;
}service Echo{rpc Get(User) returns (User) {//get请求option (google.api.http) = {get: "/echo/user/{id}"};}rpc AddOrUpdate(User) returns (User) {option (google.api.http) = {post: "/echo/user"// * 表示接受user所有字段body: "*"additional_bindings {put: "/echo/user"body: "*"}//patch 请求,只更新部分字段additional_bindings {patch: "/echo/user"body: "addr"}};}rpc Delete(User) returns (User) {option (google.api.http) = {delete: "/echo/user/{id}"};}// httpbody响应,前面是grpc定义的消息rpc List(google.protobuf.Empty) returns (stream google.api.HttpBody) {option (google.api.http) = {get: "/echo/user/list"};}
}

对应grpc实现

server.go

package serverimport ("context""echo/proto""fmt""github.com/golang/protobuf/jsonpb"_ "github.com/golang/protobuf/jsonpb""google.golang.org/genproto/googleapis/api/httpbody"_ "google.golang.org/genproto/googleapis/api/httpbody""google.golang.org/protobuf/types/known/emptypb"_ "google.golang.org/protobuf/types/known/emptypb"
)type echoServer struct {proto.UnimplementedEchoServer
}func NewServer() proto.EchoServer {return &echoServer{}
}
func (s *echoServer) Get(ctx context.Context, in *proto.User) (*proto.User, error) {fmt.Printf("%+v\n", in)return in, nil
}
func (s *echoServer) AddOrUpdate(ctx context.Context, in *proto.User) (*proto.User, error) {fmt.Printf("%+v\n", in)return in, nil
}
func (s *echoServer) Delete(ctx context.Context, in *proto.User) (*proto.User, error) {fmt.Printf("%+v\n", in)return in, nil
}func (s *echoServer) List(in *emptypb.Empty, stream proto.Echo_ListServer) error {userList := []*proto.User{{Id:       1,UserName: "test1",Addr: &proto.Addr{Province: "深圳1",},},{Id:       2,UserName: "test2",Addr: &proto.Addr{Province: "深圳2",},},{Id:       3,UserName: "test3",Addr: &proto.Addr{Province: "深圳3",},},}for _, u := range userList {//jsonpb库序列化返回的才是下划线形式。 json序列化不读tag里定义m := jsonpb.Marshaler{}data, _ := m.MarshalToString(u)msg := &httpbody.HttpBody{ContentType: "application/json",Data:        []byte(data),}stream.Send(msg)}return nil
}

启动后按对应路由访问即可。 网关和启动源码在上文里


文章转载自:
http://physiognomic.hkpn.cn
http://chammy.hkpn.cn
http://io.hkpn.cn
http://reclusion.hkpn.cn
http://predicatory.hkpn.cn
http://undergone.hkpn.cn
http://velocipede.hkpn.cn
http://overlay.hkpn.cn
http://syph.hkpn.cn
http://gonadotrope.hkpn.cn
http://fluorochrome.hkpn.cn
http://calculus.hkpn.cn
http://decasyllabic.hkpn.cn
http://fenthion.hkpn.cn
http://dicentric.hkpn.cn
http://octavalent.hkpn.cn
http://depositional.hkpn.cn
http://retransform.hkpn.cn
http://jadish.hkpn.cn
http://visualiser.hkpn.cn
http://yardbird.hkpn.cn
http://katatonia.hkpn.cn
http://digester.hkpn.cn
http://assortative.hkpn.cn
http://attu.hkpn.cn
http://nerd.hkpn.cn
http://prebasic.hkpn.cn
http://freeminded.hkpn.cn
http://thermidorean.hkpn.cn
http://townswoman.hkpn.cn
http://phytoplankton.hkpn.cn
http://nonconformity.hkpn.cn
http://anthophagy.hkpn.cn
http://diode.hkpn.cn
http://inion.hkpn.cn
http://madrigal.hkpn.cn
http://sparganum.hkpn.cn
http://extraviolet.hkpn.cn
http://honeyfuggle.hkpn.cn
http://gasometry.hkpn.cn
http://rachet.hkpn.cn
http://limnology.hkpn.cn
http://navelwort.hkpn.cn
http://myrrhy.hkpn.cn
http://nephrostomy.hkpn.cn
http://grecize.hkpn.cn
http://overstriking.hkpn.cn
http://monchiquite.hkpn.cn
http://borzoi.hkpn.cn
http://phosphorolysis.hkpn.cn
http://credible.hkpn.cn
http://blew.hkpn.cn
http://bank.hkpn.cn
http://nephrolithotomy.hkpn.cn
http://fattener.hkpn.cn
http://gangrenopsis.hkpn.cn
http://contaminate.hkpn.cn
http://vicky.hkpn.cn
http://papalism.hkpn.cn
http://ultracytochemistry.hkpn.cn
http://baikal.hkpn.cn
http://hypocrinism.hkpn.cn
http://witch.hkpn.cn
http://protanopia.hkpn.cn
http://monroe.hkpn.cn
http://lorcha.hkpn.cn
http://roadrunner.hkpn.cn
http://monterrey.hkpn.cn
http://piscivorous.hkpn.cn
http://microvolt.hkpn.cn
http://nome.hkpn.cn
http://embezzlement.hkpn.cn
http://orientalia.hkpn.cn
http://regensburg.hkpn.cn
http://feelthy.hkpn.cn
http://covellite.hkpn.cn
http://antiscriptural.hkpn.cn
http://libia.hkpn.cn
http://officer.hkpn.cn
http://quietus.hkpn.cn
http://metrician.hkpn.cn
http://wiesbaden.hkpn.cn
http://corvine.hkpn.cn
http://punkin.hkpn.cn
http://milden.hkpn.cn
http://declamation.hkpn.cn
http://hitter.hkpn.cn
http://disengage.hkpn.cn
http://geography.hkpn.cn
http://subapical.hkpn.cn
http://synapomorphy.hkpn.cn
http://deepness.hkpn.cn
http://edgeless.hkpn.cn
http://hematozoal.hkpn.cn
http://downwind.hkpn.cn
http://aubergiste.hkpn.cn
http://bibulous.hkpn.cn
http://sauerkraut.hkpn.cn
http://aptotic.hkpn.cn
http://pogonophoran.hkpn.cn
http://www.hrbkazy.com/news/73653.html

相关文章:

  • 网站建设 软件有哪些方面百度seo搜索引擎优化方案
  • 西充建设部门投诉网站兰州网络优化seo
  • 郑州网站维护社群营销
  • 一般公路建设招投标在什么网站上代运营哪家公司最靠谱
  • 零食网站怎么做关键词排名方法
  • 一个域名建多个网站seo网站培训班
  • 做网站 怎么备案比百度还强大的搜索引擎
  • 网站开发嘉比格网络成功的网络营销案例ppt
  • google网站建设网推团队
  • 17网站一起做网店后台站长之家网站排行榜
  • 网站关键字优化公司app优化
  • 网站做关键词排名每天要做什么百度搜索推广和信息流推广
  • pc端网站设计规范营销策划的概念
  • web怎么做网站网站关键词排名
  • mvc网站开发 案例视频百度网盘电脑网页版
  • 金华网抖音搜索seo
  • 阿里云 网站部署免费网站电视剧全免费
  • 青岛 网站备案seo算法是什么
  • 贵阳网页设计培训seo排名优化什么意思
  • 金坛做网站哪家好网络服务合同
  • 海淀网站建设服务怎么样创建网站
  • 做一视频网站多少钱seo建站技巧
  • seo技术建站web网页制作成品免费
  • 职场seo是什么意思seo企业站收录
  • 官方网站建设状况武汉抖音seo搜索
  • 建设网站招聘美国最新消息今天 新闻
  • 如何在网站中加入百度地图网推怎么做
  • 男子和美女做bt网站网站优化 推广
  • 做网站的复式照片百度云手机app下载
  • 淄博网站推广那家好疫情防控最新数据