英文:
How can I get remote package for Go?
问题
我在导入gin包到我的Go项目中遇到了问题。
代码:
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
正在获取 https://gopkg.in/go-playground/validator.v8?go-get=1
https获取失败: Get https://gopkg.in/go-playground/validator.v8?go-get=1: dial tcp 45.33.37.13:443: connectex: 由于目标计算机积极拒绝,无法建立连接。
包 gopkg.in/go-playground/validator.v8: 无法识别的导入路径 "gopkg.in/go-playground/validator.v8"(https获取: Get https://gopkg.in/go-playground/val
idator.v8?go-get=1: dial tcp 45.33.37.13:443: connectex: 由于目标计算机积极拒绝,无法建立连接。)
正在获取 https://gopkg.in/yaml.v2?go-get=1
https获取失败: Get https://gopkg.in/yaml.v2?go-get=1: dial tcp 45.33.37.13:
443: connectex: 由于目标计算机积极拒绝,无法建立连接。
包 gopkg.in/yaml.v2: 无法识别的导入路径 "gopkg.in/yaml.v2"(https获取: Get https://gopkg.in/yaml.v2?go-get=1: dial tcp 45.33.37.13:443: connectex: 由于目标计算机积极拒绝,无法建立连接。)
我已经在git中设置了代理设置,所以这可能是个问题吗?
英文:
I have problem with importing gin package into my Go project.
Code:
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
}
I'm using go get
command to install gin package, but it doesn't work.
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.)
I have set proxy settings in git,so can this be a problem?
答案1
得分: 2
尝试使用以下命令:
go get gopkg.in/gin-gonic/gin.v1
这将导入该框架的一个固定版本。
例如,可以参考"使用gin-gonic框架在golang中构建RESTful API服务"。
但是,如果你遇到代理问题,这个导入也会失败。正如在"使用Gin构建Go Web应用程序和微服务"中所示,使用go get -u github.com/gin-gonic/gin
也应该可以工作。
尝试在你的.gitconfig
文件中删除代理指令。
相反,尝试设置HTTP_PROXY/HTTPS_PROXY
(确保在这两种情况下都使用http URL,就像我在"这个答案"中所示的那样)。
英文:
Try with:
go get gopkg.in/gin-gonic/gin.v1
That will import a fixed version of that framework.
See for instance "Build RESTful API service in golang using gin-gonic framework"
But if you have proxy issue, that import should fail too.
As seen in "Building Go Web Applications and Microservices Using Gin", go get -u github.com/gin-gonic/gin
should work too.
Try removing proxy directive in your .gitconfig
.
Try instead setting HTTP_PROXY/HTTPS_PROXY
(make sure to use http url in both cases for the variables, as I illustrate in "this answer")
答案2
得分: 0
修复版本并不那么重要!
以下是要翻译的内容:
go get github.com/gin-gonic/gin
应该可以正常工作!修复版本是用于当你想要一个特定版本时使用的!
英文:
Fixed version is not that important!
The:
$ go get github.com/gin-gonic/gin
Should work correctly!!
Fixed version is for when you want n specific version!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论