Go mod tidy without internet

Hi! My development environment is set on a VM that is behind a proxy and does not have internet connectivity at the moment. There are errors on running go mod tidy:
module github.com/ishidawataru/sctp: Get “https://proxy.golang.org/github.com/ishidawataru/sctp/@v/list”: proxyconnect tcp: dial tcp 10.250.110.36:8000: connect: connection refused

Can something be done if I download the package source files elsewhere and place them in ~/go/pkg/mod under the correct directory or use go mod vendor?

There’s some discussion here that might be of use:

https://www.reddit.com/r/golang/comments/pxuhyb/go_mod_tidy_problem/

Why are you running go mod tidy in your VM though? You could just run it on the machine with internet access and then push the resulting tidied go.mod and go.sum to your VM.

Actually I have no way to move my code out of the VM to another Ubuntu environment that has internet. My team is working on getting around that issue. But it will take some time.

You can try to use go mod vendor else where and then move it into your project. Or as an alternative, you can try workspaces

Can you go mod vendor and tidy BEFORE you push your code to the offline VM? The bottom line is: if you want to use dependencies from the internet, you’re going to need the internet at some point in your toolchain. If you want to grab dependencies that you haven’t used in your code yet (but you know you will need) you could do imports/vendoring as suggested in this gist:

import (
	_ "github.com/gorilla/mux"
	_ "github.com/sirupsen/logrus"
)

So add all external imports you know you will need, go mod vendor them, and then push that to your offline VM.

1 Like