This project is just a challenge for me, full stack gRPC
- First
# go version: 1.23.0
cd BackEnd
go mod tidy# 这个要单独运行, 文件地址问题的原因
protoc --go_out=BackEnd\ --go-grpc_out=BackEnd\ BackEnd\proto\forum.proto
protoc --go_out=BackEnd\ --go-grpc_out=BackEnd\ BackEnd\proto\chat.proto
protoc --go_out=BackEnd\ --go-grpc_out=BackEnd\ BackEnd\proto\auth.protoMac需要用这个格式:
protoc --go_out=BackEnd --go-grpc_out=BackEnd BackEnd/proto/friend.proto
-
Second change
config/__app.ymlname toconfig/app.yml, and set the database in this file. -
Third
go run main.gocd FrontEnd
npm install
npm install -g protoc-gen-grpc-web
cd ..
protoc -I ./BackEnd/proto ./BackEnd/proto/forum.proto --js_out=import_style=commonjs:./FrontEnd/src/proto --grpc-web_out=import_style=commonjs,mode=grpcwebtext:./FrontEnd/src/proto现在是笔记时间:
- 首先我在main.go中通过viper这个包读取yml文件的内容, 然后更新到配置中, 接下来进行数据库迁移的操作,可以确保每一次启动服务的时候数据库和我的结构体是对应的.
- 然后我通过
proto/forum.proto文件生成了proto/forum.pb.go和proto/forum_grpc.pb.go文件, 这两个文件是我在golang中使用grpc的时候需要的, 通过这两个文件我可以在golang中使用grpc的服务. 其中的内容是ForumService的接口. - 接下来在
service/forumService.go中实现了ForumService的接口, 这个接口是我在proto/forum.proto文件中定义的, 通过这个接口我可以实现grpc的服务.
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. See the LICENSE file for more details.