For Question2, I have tried several times today.
If u want to build a private package safely, the most important thing you should do is setting the GOPRIVATE
BEFORE u build your package. And GONOPROXY
,GONOSUMDB
will be automatically set to same as GOPRIVATE
.
Now u can write the code and git push
to a private remote repo and try to go get
it, and u will fail and see some error message like it:
fatal: could not read Username for 'https://github.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.
The link show us that we should use https
link with your username/password or just replace your https link with ssh link if u upload a key to remote ropo. After doing it, u will succeed to go get
it from your source address (your package name) but NOT PROXY.
Futhurmore, let's delete all go module cache by using go clean -modcache
and set GOPRIVATE=""
. I will test whether our private package was uploaded to proxy.
case 1:
Set GOPROXY="https://goproxy.io"
or other proxy and thenen go get
the private package.
u will face a 404 Not Found
which show u that u find NOTHING from proxy (it meant nothing was cached/stored in proxy) .
case 2:
Set GOPROXY="direct"
(use the direct address of your pacakage name) and then go get
the private package.
u will face error message like it:
verifying {PACKAGENAME}: {PACKAGENAME}: initializing sumweb.Conn: checking tree#{ID}: Get https://sum.golang.org/tile/8/2/000.p/11: dial tcp {IP}:{PORT}: i/o timeout.
The go get
function will try to check the checksum from golang.org database with your package (I can't link to google server directly so it shows timeout error / I guess u will get 404 if u can link to google server). It shows that if we try to go get
a private package with not setting GOPRIVATE
, u will fail because u can not pass the check.
Suggestion:
If you want to build your private go package, u should set your GOPRIVATE
firstly and make sure it is wide enough to INCLUDE your package name.
Thank U to all people for reading and answering this question.