简体   繁体   English

如何将私有 go package 与模块一起使用

[英]How to use private go package with modules

I have a project which is providing an API but not under github.com, it's under github.ny.nts.com How can I use it on my code? I have a project which is providing an API but not under github.com, it's under github.ny.nts.com can I use it on my code?

I've added to a new program and in the import I put:我添加了一个新程序并在导入中放入:

import “github.ny.nts.com/fds/client”

Now when I run go mod init it didn't add anything (which is related to this project) to the go.mod file现在,当我运行 go mod init 时,它没有向 go.mod 文件添加任何内容(与此项目相关)

How can I define the “registry” (similar to nodejs/npm when you can tell from where to download the packages) on go and tell gomod to take it my company git?如何在 go 上定义“注册表”(类似于 nodejs/npm,当您可以知道从哪里下载软件包时)并告诉 gomod 将它带入我的公司 git?

I'm able to clone the project without any problem so I don't have any access problem to the project git.我能够毫无问题地克隆项目,因此我对项目 git 没有任何访问问题。

You can implicitly install the dependency by running go get in your project root like您可以通过在项目根目录中运行go get来隐式安装依赖项,例如

$> go get github.ny.nts.com/fds/client

If the repository is private you'll need to implement a workaround, as go get defaults to https for cloning git repos.如果存储库是私有的,您需要实施一种解决方法,因为go get默认设置为https用于克隆 git 存储库。 Running the following from your project folder will tell git to use SSH (and therefore your stored credentials) when pulling packages from your repo for this project:从您的项目文件夹中运行以下命令将告诉 git 在从该项目的存储库中提取包时使用 SSH(以及您存储的凭据):

$> git config insteadOf."https://github.ny.nts.com/".use "git@github.ny.nts.com:"

Once that's done, you should be able to run go get... and pull your package完成后,您应该能够运行go get...并拉动您的 package

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM