windows安装GIN环境
GIN
GitHub地址:gin-gonic/gin
Windows下搭建GIN环境
按照github给的方法,我遇到了很多问题,下面是我的安装过程和我遇到问题的解决方法。大家有问题可以一起来探讨
1.go get -u -x github.com/gin-gonic/gin 下载代码
官方给出的安装命令行是go get -u github.com/gin-gonic/gin,由于我安装的时候一直报(There is no tracking information for the current branch)这个错误,所以我加了一个-x,使用默认分支下载代码。运行这个命令,开始获取gin相关代码
2. 下载缺损代码
使用上面命令下载时,中间还是会遇到个别组件报(There is no tracking information for the current branch)的错,可能是被墙了。我们手动下载这个代码。首先,我们使用官网提供的测试代码
package main
import "github.com/gin-gonic/gin
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message" : "pong"
})
})
r.Run()
}
- 运行上面代码后你会发现,仍然报错。报错如下,意思是缺少相应的文件。
C:\Users\16196\go\src\github.com\go-playground\validator\errors.go:9:2: no Go files in C:\Users\16196\go\src\github.com\go-playground\universal-translator
C:\Users\16196\go\src\github.com\go-playground\validator\baked_in.go:19:2: no Go files in C:\Users\16196\go\src\github.com\leodido\go-urn
- 我们使用powershell进入C:\Users\16196\go\src\github.com\go-playground文件夹。使用命令(git clone https://github.com/go-playground/universal-translator)下载缺少的代码。如果报universal-translator已存在空文件夹,就把这个文件夹删掉。
- 同上,进入C:\Users\16196\go\src\github.com\leodido文件夹,使用命令(git clone https://github.com/leodido/go-urn)下载代码.
3.再次测试运行测试例程
再次尝试运行例子时,发现如下错误
C:\Users\16196\go\src\github.com\go-playground\universal-translator\errors.go:7:2: cannot find package “github.com/go-playground/locales” in any of:
c:\go\src\github.com\go-playground\locales (from $GOROOT)
C:\Users\16196\go\src\github.com\go-playground\locales (from $GOPATH)
**解决方法:**使用powerShell命令行工具进入C:\Users\16196\go\src\github.com\go-playground\文件夹下,输入指令git clone https://github.com/go-playground/locales克隆需要的代码。这个有点慢,需要等待。
4.成功运行
在浏览器中输入"127.0.0.1:8080"即可访问gin服务器,由于例子没有处理器代码,所以浏览器会返回404 not found错误。
总结
到这里,我们就成功搭建了GIN开发环境,如果大家有疑问,欢迎在评论区提出。