The ecosystem is quite spoiled with for dependency management. Composer is very straightforward and easy to use. For the ecosystem is what Composer is for PHP; Glide is the easiest and (probably) most used dependency management tool for Golang. PHP Composer Golang Glide This article compares Glide and Composer by four important Composer commands: init, install, require, and update. It does not cover . installing Glide composer init for Glide Glide also knows the “init” subcommand to initialise dependency management in your Golang project. This will set up the initial for you after asking you some questions about the package you're setting up. glide.yaml To create a for your project: glide.yaml $ glide init Glide will then create the file and it will also try to populate it. If you initialise glide on a codebase that already has dependencies mentioned in the .go source files. glide.yaml composer install for Glide Now that you know how to initialise glide in the project, it is time to install the dependencies. Composer and Glide are very similar in this aspect. To install dependencies simply call: $ glide install Glide will then install dependencies in the folder, just as Composer does. vendor/ composer require for Glide Glide’s “get” subcommand is the equivalent of Composer’s “require”. It also works much the same. Take the following two commands as an example: $ composer require rtuin/somepackage # Add a dev dependency $ composer require --dev rtuin/somepackage # Or, with version specified $ composer require rtuin/somepackage:^1.0 Glide’s counterpart, note the instead of to denote a version: # : $ glide get github.com/rtuin/somepackage # Add a dev dependency $ glide get --test github.com/rtuin/somepackage # Or, with version specified $ glide get github.com/rtuin/somepackage#^1.0 Glide respects the same way for as Composer does. denoting version numbers composer update for Glide Composer “update and Glide “update” have exactly the same results. It will find new dependency versions based on the packages listed in the file and checks if these versions need to be installed based on the version range constraints you configured. glide.yaml If any packages need to be updated Glide will, just like Composer, download this package to the folder and write the new version to the file. In the end resulting in reproducible installations. vendor/ glide.lock Glide’s composer.json Glide uses the YAML format instead of json, but other than that the essence of the file is similar to the file. glide.yaml composer.json Below you will see a file and a file to give you an idea of how similar they are. composer.json glide.yaml There are three key differences: The package definition in does not contain a version number. The package version is defined by the version control system you put your Glide-enabled package in. This can, for example, be a hash reference, revision number, or (semantic version) tag names. glide.yaml There is no “dev” import, but “test” imports. (But you can use them in the same way.) The autoload directive is not present in Glide. This is because Golang has it’s own fixed way of loading dependencies and you can’t influence them using Glide. Package loading is predictable in Golang and needs no configuration value in the dependency manager. composer.json: { "name": "rtuin/somepackage", "description": "This is some package description", "homepage": "https://github.com/rtuin/somepackage", "license": "MIT", "version": "1.0.0", "authors": [ { "name": "Richard Tuin", "email": "git@rtuin.nl", "homepage": "http://www.rtuin.nl" } ], "autoload": { "psr-4": {"Rtuin\\Somepackage": "src/"} }, "require": { "rtuin/someotherpackage": "^4.1", }, "require-dev": { "rtuin/somedevdependency": "^5.3" }} glide.yaml package: github.com/rtuin/somepackagehomepage: https://github.com/rtuin/somepackagelicense: MITowners:- name: Richard Tuin email: git@rtuin.nl homepage: http://www.rtuin.nlimport:- package: github.com/rtuin/someotherpackage version: ^4.1testImport:- package: github.com/rtuin/somedevdependency version: ^5.3 Conclusion As it turns out Golang’s Glide is very similar to PHP’s Composer. Glide is not the only popular dependency manager for Golang but it is definitely the easiest to use and it is very similar to Composer. I’ve also made this content available in slides on slideshare: Originally published at rtuin.nl .
Share Your Thoughts