Giter Club home page Giter Club logo

go-grpc-example's Introduction

grpc

Golang grpc以及grpc-gateway的简单使用

编译proto

  • 安装ProtocolBuffers以及gate-gateway,可以查找网站相关资料
  • 编译google.api
cd protos
protoc --go_out=plugins=grpc:"." "google/api/*.proto"
  • 编译*.proto
cd protos
protoc --go_out=plugins=grpc:"." ./*.proto
  • 编译*.proto.gw.go
cd protos
protoc --grpc-gateway_out=logtostderr=true:"." "*.proto"

配置使用

  • 拷贝conf/conf.toml.exmpale为conf/conf.toml,并配置数据库信息
  • 执行服务端程序:go run server.go
  • 执行客户端程序:go run client.go
  • 执行gateway程序: go run gateway.go

单元测试

go test -v
=== RUN   Test_GetArticleInfo
--- PASS: Test_GetArticleInfo (0.03s)
        article_test.go:26: golang
=== RUN   Test_GetArticleList
--- PASS: Test_GetArticleList (0.01s)
        article_test.go:41: 20
=== RUN   Test_GetCategoryInfo
--- PASS: Test_GetCategoryInfo (0.00s)
        category_test.go:22: golang
=== RUN   Test_GetCategoryList
--- PASS: Test_GetCategoryList (0.00s)
        category_test.go:37: 8
PASS
ok      grpc/tests      0.785s

性能测试

goos: windows
goarch: amd64
pkg: grpc/tests
Benchmark_GetArticleInfo-8          2000           1014170 ns/op
Benchmark_GetArticleList-8           300           4816491 ns/op
Benchmark_GetCategoryInfo-8         2000            734985 ns/op
Benchmark_GetCategoryList-8         2000            738987 ns/op
PASS
ok      grpc/tests      8.441s

go-grpc-example's People

Contributors

markbest avatar

Stargazers

sanguohot avatar  avatar colors avatar zan avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

zanjs josmel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.