我在Go项目中导入gin包时遇到了问题。
代码:
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() // listen and serve on 0.0.0.0:8080
}
我正在使用go get
命令安装gin包,但它不起作用。
C:\Users\YShipovalov\Desktop\Golang\helloworld>go get -v github.com/gin-gonic/gi
n
Fetching https://gopkg.in/go-playground/validator.v8?go-get=1
https fetch failed: Get https://gopkg.in/go-playground/validator.v8?go-get=1: di
al tcp 45.33.37.13:443: connectex: No connection could be made because the targe
t machine actively refused it.
package gopkg.in/go-playground/validator.v8: unrecognized import path "gopkg.in/
go-playground/validator.v8" (https fetch: Get https://gopkg.in/go-playground/val
idator.v8?go-get=1: dial tcp 45.33.37.13:443: connectex: No connection could be
made because the target machine actively refused it.)
Fetching https://gopkg.in/yaml.v2?go-get=1
https fetch failed: Get https://gopkg.in/yaml.v2?go-get=1: dial tcp 45.33.37.13:
443: connectex: No connection could be made because the target machine actively
refused it.
package gopkg.in/yaml.v2: unrecognized import path "gopkg.in/yaml.v2" (https fet
ch: Get https://gopkg.in/yaml.v2?go-get=1: dial tcp 45.33.37.13:443: connectex:
No connection could be made because the target machine actively refused it.)
我已经在git中设置了代理设置,所以这会是一个问题吗?
发布于 2017-08-16 13:13:33
尝试使用:
go get gopkg.in/gin-gonic/gin.v1
这将导入该框架的固定版本。
参见实例"Build RESTful API service in golang using gin-gonic framework“
但是如果你有代理问题,导入也会失败。
正如在"Building Go Web Applications and Microservices Using Gin“中所看到的,go get -u github.com/gin-gonic/gin
也应该可以工作。
尝试删除.gitconfig
中的proxy指令。
尝试设置HTTP_PROXY/HTTPS_PROXY
(确保在两种情况下变量都使用http url,如我在“this answer”中所示)
发布于 2017-08-16 13:23:57
修复的版本并不那么重要!:$ go get github.com/gin-gonic/gin
应该可以正常工作!!固定版本是为你想要n个特定的版本!
https://stackoverflow.com/questions/45705416
复制相似问题