Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vendor folder not used with 'go build'

Tags:

github

go

I'm using go-1.7 in MacOS Sierra.

My project is inside my $GOPATH/src folder and has a vendor folder inside with all its dependencies.

and I'm using the dependencies like this inside my code:

import (
"github.com/google/go-github/github"
)

Now if I run go build i get the message that all my dependencies I use could not be found inside the $GOROOT and $GOPATH on the other and adding "vendor" to my code is working:

import (
"vendor/github.com/google/go-github/github"
)

But as far as I understood it should be possible to to like in the first code snipped.

ah FYI there are no symlinks etc.

like image 413
chrisWhyTea Avatar asked Dec 25 '16 08:12

chrisWhyTea


People also ask

Should I commit vendor folder Golang?

Should I commit my vendor directory? It's the only way to get truly reproducible builds, as it guards against upstream renames, deletes and commit history overwrites. You don't need an extra dep ensure step to sync vendor/ with Gopkg. lock after most operations, such as go get, cloning, getting latest, merging, etc.

What is vendor folder in Golang?

js land, Golang's vendor folder is basically the same as Node's node_modules . It is a folder found at the root of a module that stores a copy of all the code the module depends on. The code is used to compile the final executable when the go build command is run.

What is the use of vendor folder?

"vendor" is the folder where a Drupal - composer Installation stores it's libraries. If you look at the file web/autoload. php you'll find how that works.

Should I include Git vendor?

If you're working on a sufficiently large project, it might make sense to you and your team to add vendor to your . gitignore . You'll just miss out on some amazing benefits of having all the code required to build your app stored in your source control, including: Reproducible builds.


1 Answers

From go 1.12+ go modules is the new way of handling dependencies.

  • To fix dependency version go mod init
  • To bring modules in vendor folder go mod vendor
  • To build from the vendor directory go build -mod vendor -o output
like image 107
Piyushh Avatar answered Sep 22 '22 02:09

Piyushh