I made a golang library that i re-utilize commonly between my company projects, and the repository is of course private, ive been trying to import it from github directly like you often do for 3rd party libraries, but this doesnt work as i need git authentication, afaik go package manager uses git under the hood but even using GOPRIVATE env var and replacing gitconfig url with a x-auth-basic didnt work, any precise guide on how to effectively use private repositories as modules on both windows and linux?
#importing private github module
29 messages · Page 1 of 1 (latest)
There are multiple ways to achieve this. Depends on how you are cloning your projects.
Use ssh
Gist
How to go get private repos using SSH key auth instead of password auth. - goGetPrivate.md
i cant get it to work
ive added a new ssh keypair and added it to ssh agent but when cloning i get permission denied
i created the ssh key in my acc and the private repo is of my organization, maybe has something to do with that
If you try to ssh into [email protected] what does it say
Your git instead of configuration shouldn’t include your repo just
still doesnt work
i get this error
but i did add the ssh keys
Did you try to clone the repository via ssh? Seems like something is wrong with your ssh config
yes i did
and it clones just fine
this works for me
GOPRIVATE=github.com/githubUsername/reponName go get github.com/githubUsername/reponName
you mean putting the go get in the goprivate variable?
because otherwise it doesnt work ive already tried
what did you get when you run this in your terminal
yes i am aware , sorry this might be confusing but i developed the habit of setting the env variable like this in the terminal coz i have multiple private repos .
so i change the GOPRIVATE variable each time with different repo
long story short all you need to do is to type this in the terminal
GOPRIVATE=github.com/githubUsername/reponName go get github.com/githubUsername/reponName
go will see the GOPRIVATE as env variable and then it will import the private repo to your app.
assuming you're already configured git with the credentials needed to access your private repo
are you on linux? on windows this isnt working
oh sorry yes i am on linux ,
try this
from your command prompt
set GOPRIVATE=github.com/githubUsername/repoName go get github.com/githubUsername/repoName
or
$env:GOPRIVATE = "github.com/githubUsername/repoName"
go get github.com/githubUsername/repoName
form powershell