goproxy / goproxy.cn

The most trusted Go module proxy in China.
https://goproxy.cn
MIT License
6.81k stars 393 forks source link

问题:如何引用私有仓库的子项目 #196

Closed Gold-yuan closed 9 months ago

Gold-yuan commented 10 months ago

我的项目结构如下: gomodtest .
├── go.mod
├── go.sum
├── main.go
└── utils
├── go.mod
└── utils.go

现在我在github上可以使用gomod正常的引用 gomodtest/utils像下面这样: require github.com/Gold-yuan/gomodtest/utils v0.0.0-20231208055322-99a5ec6f3f7b 但我把我的代码放在私有的gitlab上时,我可以引用github.com/Gold-yuan/gomodtest主项目,不能引用子项目了。 我想知道,可以引用子项目的功能是goproxy代理做的,还是github本身支持的?

在我本地将github.comhost映射到我的nginx转发如下方这样:

server {
    server_name  github.com;

    location ~ ^/github.com/(.*)$ {
        if ($args = "go-get=1") {
            add_header Content-Type text/html;
            return 200 '<meta name="go-import" content="$host/github.com/$1 git https://git.code.tencent.com/$1">';
        }
    }
aofei commented 10 months ago

你好。

我想知道,可以引用子项目的功能是goproxy代理做的,还是github本身支持的?

这个跟走没走 goproxy 是无关的,Go modules 是允许你这种 nested modules 的。

问题应该是出在了你的 VCS 那边,建议打开那边的日志看一下请求路径之类的是否满足要求。

另外,在使用 go getgo mod downloadgo mod tidy 等命令的时候,可以加 -x flag 来打印 go 具体执行的操作(比如发出了哪些请求之类的),方便调试。

aofei commented 9 months ago

鉴于长时间未回复,这个 issue 我就先关闭了,如果还有其他问题欢迎随时提问。