---
# System prepended metadata

title: Golang grpc
tags: [Golang]

---

---
title: Golang grpc
---
# Golang grpc
###### tags: `Golang`

環境安裝
---
```
export GO_PATH=~/go
export PATH=$PATH:/$GO_PATH/bin
```
狀況
---
1. 編譯時遇到不支援啥的，查詢後是因為版本過舊，參照下面方式
https://blog.csdn.net/kalulioo/article/details/108625443
下載以後編譯，複製到~/go/bin裡面

2. 編譯後的pb.go檔案報錯參考下面
https://blog.csdn.net/yzf279533105/article/details/104416459
https://alphagao.com/2022/03/31/resolve-conflict-with-grpc-between-etcd-and-protoc/

主要參考文章
---
https://pjchender.dev/golang/grpc-getting-started/

編譯proto
---
```
protoc *.proto --go_out=plugins=grpc:. --go_opt=paths=source_relative

protoc --go_out=plugins=grpc:. -I=${GOPATH}/src -I=. *.proto
```

import 其他.proto失敗
---
1. 需要將其他.proto放置於go_path 的src內，且不可有@的版本號
2. import同一包內的.proto，需要在執行命令指定搜尋路徑，用proto_path= 或者同意義的 -I=
3. 留意protoc-gen-go版本號，不相容時錯誤訊息也可能報 "not found or error..."


我的範例程式
---
https://github.com/ronnielin8862/go-api/tree/master/cmd/grpc

bidirectional 範例
---
https://github.com/pahanini/go-grpc-bidirectional-streaming-example/blob/master/src/client/client.go