Decentralized Application

Architecture & Development

Dependency management in Golang

Glide was one of the top tool for dependency management for Go. The Glide may become obsolete because of Dev packages introduced in Golang.
  • Message from Glide team :
"The Go community now has the dep project to manage dependencies. Please consider trying to migrate from Glide to dep. Glide will continue to be supported for some time but is considered to be in a state of support rather than active feature development."
dep is a prototype dependency management tool for Go. It requires Go 1.9 or newer to compile. dep is safe for production use. Initially there was planning to integrate deployment into go 1.10.x version but still it has long way. So now you have to install and use separately.
  • Install dep package

  • $ brew install dep
  • $ brew upgrade dep
  • Create the project inside $GOPATH

  • Create new project under $GOPATH/src/elasticcloudapps.com/hellodep
  • package main
  • import (
  • )
  • func main() {
  • }
  • Initialize dep
  • Dep needs two files called Gopkg.lock and Gopkg.toml. You can initialize these files with following
  • $ dep init
  • Locking in master (d644981) for transitive dep golang.org/x/crypto
  • Locking in master (2281fa9) for transitive dep golang.org/x/sys
  • Using ^1.0.5 as constraint for direct dep github.com/sirupsen/logrus
  • Locking in v1.0.5 (c155da1) for direct dep github.com/sirupsen/logrus
  • After this the new files will be generated.
The Gopkg.lock serves exactly the same function as the glide.lock file. It locks the version of the packages EXCEPT the version should be maintained in the Gopkg.toml. In short, the Gopkg.lock file is auto-generated and it depends on the import statements in the source version controlled by Gopkg.toml.

Following are the examples for dep command.
dep init set up a new project
dep ensure install the project's dependencies
dep ensure -update update the locked versions of all dependencies
dep ensure -add github.com/pkg/errors add a dependency to the project