方式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即可。每次更改源文件,代码将自动重新编译