1

How to provide dependencies for go project, when I can only download the dependencies via browser?

I manually placed dependencies at GOPATH, but still go build is trying to reach internet to download dependencies

mpromonet
  • 11,326
  • 43
  • 62
  • 91

1 Answers1

2

It's recommended to use Go Modules to manage a project and its dependencies. Go modules also have the vendor feature.

When vendor is enabled, local copy of your dependencies will be stored in vendor folder within your project. So then when you transfer the whole source code into the server, you don't need to download the dependencies again, since it's already included in the project.

novalagung
  • 10,905
  • 4
  • 58
  • 82
  • 3
    I would suggest using go modules to manage vendor now, rather than any of those tools, most of which have been deprecated. – JimB Feb 20 '20 at 15:55
  • So I went to the docs for Go Modules. IMO, it's so general as to be without meaning for me. Or maybe I'm stupid. – El Ingeniero Feb 20 '20 at 17:00
  • 1
    @ElIngeniero basically what you need to do is: 1. in your local, run go mod init blablabla inside the project; 2. go get all dependencies; 3. go mod vendor; 4. archive/zip the whole source code; 5. send it to the server; 6. unzip; 7. go build and then run. 8. done – novalagung Feb 20 '20 at 17:09
  • "go get" does not work on my workstation: there's a whitelist of apps that can do https and neither Go nor Git is whitelisted. I need to download with a browser, and put it somewhere. I tried unzipping to $GOPATH/src/github.com// and then "go build && go install" in the unzipped dir. But when I went to try to build, go tries to download it again. – El Ingeniero Feb 20 '20 at 17:37
  • go get is a fundamental tool to get your libraries i suggest you ask for it to be white listed or keeping track of dependencies and their version will be a pain – Pizza lord - on strike Feb 04 '22 at 15:24