-2

I want to know about vendor folder in a Go project.

I cloned a go repo and made my code changes. But when I try to run the related test I got some error messages. On some google search, I found that I need to run some commands:

  • go mod tidy

  • go mod vendor

Now issues are gone, but I see a large number of files in vendor folder have changed.

Is it acceptable?

Do I need to commit all these file?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Mandroid
  • 6,200
  • 12
  • 64
  • 134
  • 3
    The reason to use `vendor/` is to commit the files. If you don’t want to do that, then you don’t need `vendor` – JimB Apr 07 '23 at 10:31

1 Answers1

-1

vendor folder contains all dependencies of the project so it usually is not committed to the repository.

You should however commit go.mod and go.sum files, if there is nothing sketchy with libs you depend on (removing version, sources etc), vendor folder should be fully reproducible from the go.sum file.

With Go modules vendor folder is rarely used tho. Most people do not use it locally either. Running go mod download instead of go mod vendor would download modules to a modules directory on your system (by default $GOPATH/pkg).

You can read more about vendoring with Go modules in docs. Or checkout the whole Go modules documentation https://go.dev/ref/mod.

Szymig
  • 555
  • 5
  • 9
  • 1
    The only purpose of censoring is to commit the vendord stuff and be able to work offline. If vendoring then commit. Just don’t vendor. – Volker Apr 07 '23 at 06:45
  • 2
    If you’re not going to commit the vendor directory, then there is no point of using it at all. The purpose of having it is to commit the files. – JimB Apr 07 '23 at 11:06
  • s/censoring/vendoring/ (stupid auto correction). – Volker Apr 07 '23 at 12:25
  • `vendor folder is rarely used tho.` - not true. There are very legitimate reasons to use `go mod vendor` as [outlined here](https://stackoverflow.com/questions/68544611/what-is-the-purpose-of-go-mod-vendor-command). – colm.anseo Apr 07 '23 at 15:07