gpt4 book ai didi

git - 如何获取 Go 的远程包?

转载 作者:IT王子 更新时间:2023-10-29 01:41:22 27 4
gpt4 key购买 nike

我在将 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
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 中设置了代理设置,所以这会是个问题吗?

最佳答案

尝试:

  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 中的代理指令。

尝试设置 HTTP_PROXY/HTTPS_PROXY(确保在这两种情况下都为变量使用 http url,如我在“this answer”中所示)

关于git - 如何获取 Go 的远程包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45705416/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com