1. 環境變數:/etc/profile或其他檔案
export GOROOT=/usr/local/go
export GOPATH=$HOME/golang
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin:$HOME/bin/protoc
export GOPROXY=https://goproxy.cn
export GO111MODULE=on
2. 建golang目錄
# mkdir $HOME/golang
# mkdir $HOME/golang/src
# mkdir $HOME/golang/pkg
# mkdir $HOME/golang/bin
3. 下載golang
https://studygolang.com/dl
# tar -xf xx -C /usr/local/
4. 安裝protoc
原始碼地址:https://github.com/protocolbuffers/protobuf/releases
下載3.14版本
# curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-linux-x86_64.zip -o protoc-3.14.0-linux-x86_64.zip
# mkdir protoc
# mv protoc-3.14.0-linux-x86_64.zip protoc/
# yum install unzip -y
# cd protoc
# unzip protoc-3.14.0-linux-x86_64.zip
# cp bin/protoc $GOPATH/bin/
# cp -r include/google $HOME/src/
5. 需要gcc
# yum install gcc -y
6. 快速開始
https://go-kratos.dev/#/quickstart
# go get -u github.com/go-kratos/kratos/tool/kratos
不用到$GOPATH目錄,使用go module,隨便創建一個目錄即可:
# mkdir kratosL && cd kratos
新建app:
# kratos new app01
初始化go module:
# go mod init kratosL
自動獲取依賴:
# go mod tidy
運行:
# cd app01/cmd
# go build
# ./cmd -conf ../configs
如下地址:
http://172.20.42.54:8000/app01/start
瀏覽器回傳:
{"code":0,"message":"0","ttl":1,"data":{"Hello":"Golang 大法好 !!!"}}
問題1:執行 kratos new app01
kratos tool protoc --grpc --bm api.proto
2020/12/29 16:07:29 protoc --proto_path=/root/golang/src --proto_path=/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.1-0.20201222142230-f9d8abbcc47a/third_party --proto_path=/root/kratosL/app01/api --bm_out=:. api.proto
api.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
解決:protoc版本過低
問題2:安裝gcc時報錯
錯誤:軟體包:glibc-2.17-292.el7.i686 (base)
需要:glibc-common = 2.17-292.el7
已安裝: glibc-common-2.17-307.el7.1.x86_64 (@anaconda)
glibc-common = 2.17-307.el7.1
可用: glibc-common-2.17-292.el7.x86_64 (base)
glibc-common = 2.17-292.el7
您可以嘗試添加 --skip-broken 選項來解決該問題
您可以嘗試執行:rpm -Va --nofiles --nodigest
yum downgrade glibc-common glibc -y
已安裝版本過高,需要降級
問題3:grpc版本過高問題
go run main.go --conf ../configs
/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.0/pkg/net/rpc/warden/balancer/p2c/p2c.go:34:5: cannot use &p2cPickerBuilder literal (type *p2cPickerBuilder) as type base.PickerBuilder in assignment:
*p2cPickerBuilder does not implement base.PickerBuilder (wrong type for Build method)
have Build(map[resolver.Address]balancer.SubConn) balancer.Picker
want Build(base.PickerBuildInfo) balancer.Picker
/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.0/pkg/net/rpc/warden/balancer/p2c/p2c.go:35:5: cannot use &p2cPicker literal (type *p2cPicker) as type balancer.Picker in assignment:
*p2cPicker does not implement balancer.Picker (wrong type for Pick method)
have Pick(context.Context, balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error)
want Pick(balancer.PickInfo) (balancer.PickResult, error)
/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.0/pkg/net/rpc/warden/balancer/p2c/p2c.go:42:32: not enough arguments in call to base.NewBalancerBuilder
have (string, *p2cPickerBuilder)
want (string, base.PickerBuilder, base.Config)
/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.0/pkg/net/rpc/warden/balancer/p2c/p2c.go:144:2: cannot use p (type *p2cPicker) as type balancer.Picker in return argument:
*p2cPicker does not implement balancer.Picker (wrong type for Pick method)
have Pick(context.Context, balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error)
want Pick(balancer.PickInfo) (balancer.PickResult, error)
修改go.mod,降為v1.29.1 google.golang.org/grpc v1.29.1
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/242916.html
標籤:區塊鏈
上一篇:golang:cannot unmarshal number into Go value of type []json.RawMessage
下一篇:ELECTRA
