https://github.com/navono/grpc-http-rest
https://github.com/navono/grpc-http-rest
client-grpc grpc grpc-gateway
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/navono/grpc-http-rest
- Owner: navono
- Created: 2018-12-25T04:52:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-02T12:20:42.000Z (almost 7 years ago)
- Last Synced: 2025-03-11T18:54:57.392Z (about 1 year ago)
- Topics: client-grpc, grpc, grpc-gateway
- Language: Go
- Size: 89.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dev
## 基本
- 下载 [protobuf](https://github.com/protocolbuffers/protobuf/releases) 编译工具,将 `bin` 加入到环境变量
- 下载安装 `golang` 版本的插件
> go get -u -v github.com/golang/protobuf/protoc-gen-go
- 编译
> protoc --proto_path=api/proto/v1 --proto_path=third_party --go_out=plugins=grpc:pkg/api/v1 todo-service.proto
- 数据库依赖于运行在 `Docker` 中的 `MySQL`,启动 `MySQL` 容器:
> ./third_party/db.cmd
如果数据库客户端(navicat)链接不上:
> docker exec -it todo-mysql bash
>
> mysql -u root -p
>
> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
>
> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
>
> FLUSH PRIVILEGES;
## grpc-gateway
安装依赖:
> go get -u -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
>
> go get -u -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
找到 `grpc-gateway` 的安装目录,我这是在
```sh
%GOPATH%\pkg\mod\github.com\grpc-ecosystem\grpc-gateway@v1.6.2\third_party\googleapis\google
```
将安装目录下的 `protoc-gen-swagger/options` 下的 proto 文件拷贝到工程目录下的 `third_party\protoc-gen-swagger\options`。
# 测试
编译时可能需要科学上网。
## grpc
### 服务器端
- 手动编译
> cd cmd/server
>
> go build .
运行:
> .\server.exe -grpc-port=9090 -http-port=8080 -db-host=localhost:3306 -db-user=root -db-password=123456 -db-schema=todo -log-level=-1 -log-time-format=2006-01-02T15:04:05.999999999Z07:00
- 容器
构建镜像:
> .\scripts\buildImage.cmd
启动:
> .\scripts\start.cmd
停止:
> .\scripts\clean.cmd
### rpc客户端
编译:
> cd cmd/client-grpc
>
> go build .
运行:
> .\client-grpc.exe -server=localhost:9090
### rest客户端
编译:
> cd cmd/client-rest
>
> go build .
运行:
> .\client-rest.exe -server=http://localhost:8080