简体   繁体   中英

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'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

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?

I'm able to clone the project without any problem so I don't have any access problem to the project git.

You can implicitly install the dependency by running go get in your project root like

$> 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. 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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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