gpt4 book ai didi

go - 仅从内部代理下载私有(private)模块并从外部代理获取公共(public)模块

转载 作者:行者123 更新时间:2023-12-01 21:13:07 25 4
gpt4 key购买 nike

我开始迁移一个 Go 项目以使用模块进行依赖管理。我的公司有一个仅托管私有(private)模块的内部 go 代理。所以,我需要一种从内部代理下载 PRIVATE 模块的方法,比如说 goproxy.company.com以及 golang.org/x/tools/cmd/goimports 等公共(public)模块和 github.com/sirupsen/logrus来自公开可用的 go 代理,例如 proxy.golang.org .我以为这会解决它。GOPROXY='goproxy.company.com,proxy.golang.org,direct'GPPRIVATE=*.company.com/*但是,在尝试了第一个代理和第二个代理后它失败了,并且从不使用 direct选项作为后备。这是一个已知问题还是我在这里做错了什么?
有一个更好的方法吗?托管公开可用的 go 模块的公司内部代理是否正常?这是普遍的预期吗?
阅读文档后,我有这种感觉。以下是引用资料。

As mentioned in the Proposal: Secure the Public Go Module Ecosystem

We expect that corporate environments may fetch all modules, public and private, through an internal proxy;



Also, in the go docs example for a corporate proxy

For example, if a company ran a module proxy serving private modules, users would configure go using:

GOPRIVATE=*.corp.example.com 
GOPROXY=proxy.example.com
GONOPROXY=none

This would tell the go command and other tools that modules beginningwith a corp.example.com subdomain are private but that the companyproxy should be used for downloading both public and private modules,because GONOPROXY has been set to a pattern that won't match anymodules, overriding GOPRIVATE.

最佳答案

Go 1.15 添加了一个功能,现在允许您设置 GOPROXY跳过代理。
来自 Go 1.15 Release Notes :

The GOPROXY environment variable now supports skipping proxies thatreturn errors. Proxy URLs may now be separated with either commas (,)or pipe characters (|). If a proxy URL is followed by a comma, the gocommand will only try the next proxy in the list after a 404 or 410HTTP response. If a proxy URL is followed by a pipe character, the gocommand will try the next proxy in the list after any error. Note thatthe default value of GOPROXY remains https://proxy.golang.org,direct,which does not fall back to direct in case of errors.


这应该允许您设置 GOPROXY正如您在问题中指出的那样。

关于go - 仅从内部代理下载私有(private)模块并从外部代理获取公共(public)模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62527648/

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