Go Zero
This is to study go zero
- 轉換proto文件
goctl rpc protoc user/rpc/user.proto --go_out=user/rpc/types --go-grpc_out=user/rpc/types --zrpc_out=user/rpc/
- OR
goctl rpc protoc user.proto --go_out=types --go-grpc_out=types --zrpc_out=.
- 將要改變地方寫在/internal/logic/getuserlogic 裡面
- 設定好地址 : grpc://localhost:[port]
- 導入proto 後按next再選擇設定地址旁邊的input
- 轉換api文件
goctl api go -api video/api/video.api -dir video/api/
- 修改/internal/config/config.go
- 修改/internal/svc/servicecontext.go
- 將要改變地方寫在/internal/logic/getVideologic 裡面
- 開啟etcd服務器,終端輸入etcd (在專案根目錄執行)
- 開啟rpc服務 go run user.go
- 開啟api服務 go run api.go
- 將yaml配置文欓中的地址改為localhost而非etcd
- 重開電腦
- 生成模板文件
goctl template init
- 更改模板文件會再生成api文黨時進行變更
goctl api go -api user.api -dir .
- 使用sqlx
- 使用gorm
- 編寫common/init_gorm/enter.go來啟動db連接
- 編寫svc/servicecontext.go和config/config.go
- 編寫logic/loginlogic.go測試gorm是否可以正確運行