使内部 go 模块可供更多项目使用

问题描述 投票:0回答:1

在我的一个项目中,我使用了一个内部模块:

package main

import (
    "gitlab.example.com/team/project/internal/exitcodes"
)

效果很好。

现在我在另一个项目中也需要该模块,但我未能实现。

首先,我创建了一个新的存储库,在其中放置模块:gitlab.example.com/team/gocommon

并将导入相应更改为“gitlab.example.com/team/gocommon/exitcodes”。

然后我创建了一个accesstoken并将其放入~/.netrc

machine gitlab.example.com
    login gogettoken
    password DBJMsPsGrFAiMq2MDRRT

但是项目无法构建:

gitlab.example.com/team/gocommon/exitcodes: gitlab.example.com/team/[email protected]: verifying module: gitlab.example.com/team/[email protected]: reading https://sum.golang.org/lookup/gitlab.example.com/team/[email protected]: 404 Not Found
server response:
not found: gitlab.example.com/team/[email protected]: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/5c5d3cb0b00b8d48278234b7d0c82797966117d16c9fedbd2cf87e471d549e5b: exit status 128:
        fatal: could not read Username for 'https://gitlab.example.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

我已经检查了提到的 golang.org 链接,但它并没有帮助我找到解决方案。

go module gitlab
1个回答
0
投票

看起来您在使用 ssh git 和 https git 时遇到问题。你们公司有人已经这样做了吗?可能存在一些安全问题。

检查一些没有顺序的东西,这个列表中的任何一个都可能对你有帮助:

  • 尝试 git clone 你的新仓库,有什么问题吗?是 git url 还是 https?
  • 您可以访问该存储库(看起来是您的,所以我认为答案是肯定的)
  • 奔跑
    go mod tidy
  • 尝试将 .netrc 添加到项目文件夹中。我从 ~/.netrc 看到的一些系统由于某种原因无法工作
  • 将.netrc的内容放在一行中
  • 用手尝试
    go get <package>
  • 您是否使用 .netrc 中的密码或来自 gitlab 的令牌?我觉得应该是token。
© www.soinside.com 2019 - 2024. All rights reserved.