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()
}
  1. 运行上面代码后你会发现,仍然报错。报错如下,意思是缺少相应的文件。

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

  1. 我们使用powershell进入C:\Users\16196\go\src\github.com\go-playground文件夹。使用命令(git clone https://github.com/go-playground/universal-translator)下载缺少的代码。如果报universal-translator已存在空文件夹,就把这个文件夹删掉。
  2. 同上,进入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开发环境,如果大家有疑问,欢迎在评论区提出。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值