Tom Ratcliff1 min read
Offline Go Modules
Work in airgapped enviroments with Golang
Using go mod vendor
With an existing module
- copy
go.mod and go.sum files from the offline PC to the internet PC
New module
- create a folder on machine with internet access
- create a go module :
go mod init offline
Download dependencies via vendor folder
- create a
offline_modules.go file :
- add the dependencies you want to download (use
_) :
package offline_modules
import (
_ "github.com/gorilla/mux"
_ "github.com/sirupsen/logrus"
)
func main() {}
- To download dependencies, run:
- the vendor folder should have new folders in it representing dependencies
Back to offline
- copy
go.mod, go.sum and vendor directory to offline machine - run your go commands with the flag
-mod=vendor like:
go run -mod=vendor main.go
No comments yet