首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何获取Go的远程包?

如何获取Go的远程包?
EN

Stack Overflow用户
提问于 2017-08-16 13:01:48
回答 2查看 1.5K关注 0票数 2

我在Go项目中导入gin包时遇到了问题。

代码:

代码语言:javascript
运行
复制
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包,但它不起作用。

代码语言:javascript
运行
复制
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中设置了代理设置,所以这会是一个问题吗?

EN

回答 2

Stack Overflow用户

发布于 2017-08-16 13:13:33

尝试使用:

代码语言:javascript
运行
复制
  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”中所示)

票数 2
EN

Stack Overflow用户

发布于 2017-08-16 13:23:57

修复的版本并不那么重要!:$ go get github.com/gin-gonic/gin应该可以正常工作!!固定版本是为你想要n个特定的版本!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45705416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档