Skip to content

Commit

Permalink
refactor grpc (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuwensun committed Mar 5, 2020
1 parent 11b0bb0 commit f6696ad
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 142 deletions.
4 changes: 4 additions & 0 deletions doc/开发规范.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ MD 规范 https://github.com/fuwensun/Markdown
分支规范(2) https://blog.csdn.net/qq_33858250/article/details/81047883
发布规范(1) https://www.cnblogs.com/hrhguanli/p/5066549.html
发布规划(2) https://www.zhihu.com/question/21127832
API规范 https://www.cnblogs.com/moonz-wu/p/4211626.html


## goms 项目
工程 https://github.com/fuwensun/goms/projects/1
Expand Down Expand Up @@ -68,4 +70,6 @@ Given a version number MAJOR.MINOR.PATCH, increment the:

主干开发,分支发布


...

10 changes: 5 additions & 5 deletions eGrpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ rpc 服务,使用 grpc 包.

protoc
```
cd goms/eGrpc/api/pb
cd goms/eGrpc/api/grpc/pb
# 执行 pb.go 文件头的指令
go generate ./pb.go
```
>pb.go 文件
//go:generate protoc --go_out=plugins=grpc:../ call.proto
//go:generate protoc --go_out=plugins=grpc:../ api.proto

## 运行服务
```
Expand All @@ -36,6 +36,6 @@ grpc
# 获取 grpc 方法列表
grpcurl -plaintext localhost:50051 list
# 使用 grpc 方法 api.Call/Ping, 参数 {"Message": "xxx"}
grpcurl -plaintext -d '{"Message": "xxx"}' localhost:50051 api.Call/Ping
``
# 使用 grpc 方法 service.goms.User/Ping, 参数 {"Message": "xxx"}
grpcurl -plaintext -d '{"Message": "xxx"}' localhost:50051 service.goms.User/Ping
```
79 changes: 40 additions & 39 deletions eGrpc/api/call.pb.go → eGrpc/api/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions eRedis/api/pb/call.proto → eGrpc/api/pb/api.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//
syntax = "proto3";

package api;
package service.goms; //和 service 一起组成服务名称

service Call{
option go_package = "api"; //生成的 go 包的包名

service User{
rpc Ping(Request)returns(Reply){};
}

Expand Down
2 changes: 1 addition & 1 deletion eGrpc/api/pb/pb.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//go:generate protoc --go_out=plugins=grpc:../ call.proto
//go:generate protoc --go_out=plugins=grpc:../ api.proto
package pb
2 changes: 1 addition & 1 deletion eGrpc/internal/server/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func New(s *service.Service) (server *Server) {
log.Fatalf("failed to listen: %v", err)
}
xs := xrpc.NewServer()
api.RegisterCallServer(xs, server)
api.RegisterUserServer(xs, server)
reflection.Register(xs)

go func() {
Expand Down
4 changes: 2 additions & 2 deletions eGrpc/internal/server/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func New(s *service.Service) (engine *gin.Engine) {

//
func initRouter(e *gin.Engine) {
g := e.Group("/call")
v1 := e.Group("/v1")
{
g.GET("/ping", ping)
v1.GET("/ping", ping)
}
}

Expand Down
5 changes: 2 additions & 3 deletions eMysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ grpc
# 获取 grpc 方法列表
grpcurl -plaintext localhost:50051 list
# 使用 grpc 方法 api.Call/Ping, 参数 {"Message": "xxx"}
grpcurl -plaintext -d '{"Message": "xxx"}' localhost:50051 api.Call/Ping
# 使用 grpc 方法 service.goms.User/Ping, 参数 {"Message": "xxx"}
grpcurl -plaintext -d '{"Message": "xxx"}' localhost:50051 service.goms.User/Ping
```
Loading

0 comments on commit f6696ad

Please sign in to comment.