grpc-gateway

栏目: 服务器 · 发布时间: 7年前

内容简介:win10,eclipse安装好go(gopath,gobin 设置好)go get -u google.golang.org/grpc

1.环境

win10,eclipse

安装好go(gopath,gobin 设置好)

a. 安装好 grpc-go

go get -u google.golang.org/grpc

如果被墙,git clone 到go path 相关目录

git clone https://github.com/grpc/grpc-go

b.安装 go get -u github.com/golang/protobuf/protoc-gen-go

c. 安装 Grpc-gateway

go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

d.生成proxy 基本依赖

protoc -I. -I%GOPATH%/src -I%GOPATH%/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. helloWorld.proto

e:main类

package main

import (

"flag"

"net/http"

"github.com/golang/glog"

"github.com/grpc-ecosystem/grpc-gateway/runtime"

"golang.org/x/net/context"

"google.golang.org/grpc"

)

var (

echoEndpoint = flag.String("echo_endpoint", "localhost:9090", "endpoint of YourService")

)

func run() error {

ctx := context.Background()

ctx, cancel := context.WithCancel(ctx)

defer cancel()

mux := runtime.NewServeMux()

opts := []grpc.DialOption{grpc.WithInsecure()}

err := RegisterHellowordServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint, opts)

if err != nil {

return err

}

return http.ListenAndServe(":8080", mux)

}

func main() {

flag.Parse()

defer glog.Flush()

if err := run(); err != nil {

glog.Fatal(err)

}

}

f.启动9090端口server java类,启动poxy main

g: post man 测试


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

众包

众包

杰夫·豪 / 牛文静 / 中信出版社 / 2009-6 / 36.00元

本书是继《长尾理论》之后的重要商业书籍。本书回答了《长尾理论》遗留的一大悬念。在长尾中作者详细阐述了长尾之所以成为可能的一个基础,但是没有详细解读,本书就是对这一悬念的详细回答,是《长尾理论》作者强力推荐的图书,在国际上引起了不小的轰动,“众包”这一概念也成为一个标准术语被商界广泛重视。本书大致分为三个部分,介绍众包的现在、过去和未来,解释了它的缘起、普遍性、力量以及商业上的适用性,通俗易懂,精彩......一起来看看 《众包》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

SHA 加密
SHA 加密

SHA 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具