方式1:直接使用go get函數,該情況下,已經配置好go環境變量
go get gopkg.in/gin-gonic/gin.v1
但是,使用該語句的時候,遇見超時的問題,可能是內網或者go get被牆(大概率)的原因,此方法行不通
方法2:先采用git clone方法下載gin包,再使用go install安裝
(1)下載到當前終端所在路徑:git clone https://github.com/gin-gonic/gin.git
(2)安裝:go install github.com/gin-gonic/gin
提示這兩個文件夾不存在,於是依然采用git clone下載
參考:https://www.jianshu.com/p/18d1f04be18e
具體語句:
git clone --branch v8.18.2 https://github.com/go-playground/validator.git
git clone --branch v2.2.1 https://github.com/go-yaml/yaml.git
然后將下載下來的包改名,分別為:
gopkg.in\go-playground\validator.v8
gopkg.in\yaml.v2
存放到GOPATH下的
src\github.com\gin-gonic\gin\vendor\gopkg.in 中
具體依據錯誤出現的路徑提示
再執行:go install github.com/gin-gonic/gin
報錯如下:
unrecognized import path "google.golang.org/protobuf/encoding/prototext": https fetch: Get "https://google.golang.org/protobuf/encoding/prototext?go-get=1": dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
unrecognized import path "google.golang.org/protobuf/encoding/protowire": https fetch: Get "https://google.golang.org/protobuf/encoding/protowire?go-get=1": dial tcp 216.239.37.1:443: i/o timeout
mabing@mabingdeMacBook-Pro logger % go get -u github.com/golang/protobuf/proto
unrecognized import path "google.golang.org/protobuf/encoding/prototext": https fetch: Get "https://google.golang.org/protobuf/encoding/prototext?go-get=1": dial tcp 216.239.37.1:443: i/o timeout
unrecognized import path "google.golang.org/protobuf/encoding/protowire": https fetch: Get "https://google.golang.org/protobuf/encoding/protowire?go-get=1": dial tcp 216.239.37.1:443: i/o timeout
unrecognized import path "google.golang.org/protobuf/proto": https fetch: Get "https://google.golang.org/protobuf/proto?go-get=1": dial tcp 216.239.37.1:443: i/o timeout
unrecognized import path "google.golang.org/protobuf/reflect/protoreflect": https fetch: Get "https://google.golang.org/protobuf/reflect/protoreflect?go-get=1": dial tcp 216.239.37.1:443: i/o timeout
unrecognized import path "google.golang.org/protobuf/reflect/protoregistry": https fetch: Get "https://google.golang.org/protobuf/reflect/protoregistry?go-get=1": dial tcp 216.239.37.1:443: i/o timeout
unrecognized import path "google.golang.org/protobuf/runtime/protoiface": https fetch: Get "https://google.golang.org/protobuf/runtime/protoiface?go-get=1": dial tcp 216.239.37.1:443: i/o timeout
unrecognized import path "google.golang.org/protobuf/runtime/protoimpl": https fetch: Get "https://google.golang.org/protobuf/runtime/protoimpl?go-get=1": dial tcp 216.239.37.1:443: i/o timeout
解決辦法:
項目代碼托管在coding上,國內訪問應該快一點
地址:https://robinqiwei.coding.net/p/googleprotobuf/git
LINUX上執行下面的命令:
mkdir -p $GOPATH/src/google.golang.org
git clone https://e.coding.net/robinqiwei/googleprotobuf.git $GOPATH/src/google.golang.org/protobuf
安裝動態刷新
go get -v -u github.com/pilu/fresh
安裝好后,只需要將go run main.go
命令換成fresh
即可。每次更改源文件,代碼將自動重新編譯