How to add a package to godeps

1.9k Views Asked by At

I Already have a existing project in github and have deps json file stored in Godeps folder and dependency packages in vendor folder.

Now I need a way to add a new package to the list without effecting anything to the existing json file and vendor package folder

1

There are 1 best solutions below

0
On BEST ANSWER

Don't fight the tooling. Let godep update your json file and vendor folder, no matter how much it disturbs your pristine Godeps/godeps.json file.

godep restore     // put everything in a known state
go get -u foo/bar // get new package
go test ./...     // make sure everything is up to snuff
go run main.go    // run your code
godep save ./...  // update `godeps.json` to current state of packages

If you use go get -u foo/bar for your new package, this only affects your new package of foo/bar - it does not update your existing packages.

The -u flag instructs get to use the network to update the named packages and their dependencies. By default, get uses the network to check out missing packages but does not use it to look for updates to existing packages. https://golang.org/cmd/go/

As a side note, I recommend getting in the habit of using godep prefixes so not to disburb your $GOPATH:

go get -u foo/bar     // get new package
godep go test ./...   // test your package, using your /vendor deps
godep go run main.go  // run your code, using your /vendor deps
godep save ./...      // update godeps if everything checks out

It makes switching multiple repos much easier.

Tip: make your configuration defaults sensible for your "local development environment" for your team. E.g. DB username/password like "dev/dev" and so on. That way, you don't have to pass parameters with godep go run main.go. Nice and simple.