Go包管理gpm簡介

來源:互聯網
上載者:User
gpm is a minimalist package manager for Go that leverages the power of the `go get` command and the underlying version control systems used by it to set your Go dependencies to desired versions, thus allowing easily reproducible builds in your Go projects. Go Package Manager makes no assumptions about your dependencies and supports Git, Bazaar and Mercurial hosted Go packages, for a smoother workflow be sure to check out [gvp](https://github.com/pote/gvp) - the Go Versioning Packager which provides dependency isolation for your projects. 1 一行安裝gpm
wget https://raw.githubusercontent.com/pote/gpm/v1.4.0/bin/gpm --no-check-certificate && chmod +x gpm && sudo mv gpm /usr/local/bin
2 The Godeps file

gpm expects you to have a file called Godeps in the root of your Go application in the format 2.1 Packages

You can specify packages with the format, where version can be a revision number (a git/bazaar/mercurial/svn revision hash) or a tag.

$ ls .Godeps  foo.go  foo_test.go$ cat Godepsgithub.com/nu7hatch/gotrail               v0.0.2github.com/replicon/fast-archiver         v1.02launchpad.net/gocheck                     r2013.03.03   # Bazaar repositories are supportedcode.google.com/p/go.example/hello/...    ae081cd1d6cc  # And so are Mercurial ones
Comments

The Godeps file accepts comments using a # symbol. Everything to the right of a # will be ignored by gpm, as well as empty lines. Extensibility

As a convention comments can be used to specify lines that gpm core should ignore but are instead intended to affect how a given gpm plugin behaves.

For example: a hypothetical gpm-track plugin that makes sure a given package is always updated to its last possible version would leverage a line like this one:

[gpm-track] github.com/nu7hatch/gotrail

This convention makes the Godeps file format extensible, just as with plugins this can help identify common needs that might later on be merged into core without having to sacrifice code simplicity in order to explore new features. Private Repos

Both gpm and go get support using private GitHub repositories! Here’s what you need to do in order for a specific machine to be able to access them: Generate a GitHub access token by following these instructions. Add the following line to the ~/.netrc file in your home directory.

machine github.com login <token>

You can now use gpm (and go get) to install private repositories to which your user has access! :) Completeness

It is recommended to keep a healthy and exhaustive Godeps file in the root of all Go project that use external dependencies, remember every package that you add to the Godeps file will be installed along with its dependencies when gpm runs go get on it, so if you don’t include these dependencies in your Godeps file you are losing the ability to reproduce a build with 100% reliability.

Make sure your Godeps file is exhaustive, this way any project includes the documentation required to be built reliably at any point in time. Commands

gpm has the following commands:

$ gpm             # Same as 'install'.$ gpm get         # Parses the Godeps file, gets dependencies and sets them                  # to the appropriate version but does not install them.$ gpm install     # Parses the Godeps file, installs dependencies and sets                  # them to the appropriate version.$ gpm version     # Outputs version information$ gpm help        # Prints this message
Plugins

As of version v1.1.1 gpm supports plugins, the intent of which is the ability to add powerful non-core features to gpm without compromising the simplicity of its codebase.

The way gpm plugin works is simple: whenever an unknown command is passed into gpm it will look for an executable in your $PATH called gpm-<command> and if it exists it will run it while passing all extra arguments to it, simple yet powerful.

This brings a lot to the table: plugins can be written in anything, they can be Go binaries, bash scripts, Ruby gems, Python packages, you name it. gpm wants to make it easy for you to extend it. :) Installing plugins through Homebrew

I maintain a repository with homebrew formulae for gpm plugins that you can add to your system with the brew tap command:

$ brew tap pote/gpm_plugins

After you’ve done this you can install plugins as you would with any other homebrew packge.

$ brew install gpm-bootstrap
Known Plugins

If you have written a gpm plugin and want it included please send a pull request to the repo! I love how people have taken to explore possible features using plugins so if you’ve written one there is about a 99% chance I will include it here. :)

Name and Link Author Short Description Type
gpm-bootstrap pote Creates an initial Godeps file official
gpm-git technosophos Git management helpers third party
gpm-link elcuervo Dependency vendoring third party
gpm-local technosophos Usage of local paths for packages third party
gpm-prebuild technosophos Improves building performance third party
gpm-all pote Installs multiple sets of deps official
gpm-lock zeeyang Lock down dependency versions third party

There is no real difference on official/third party plugins other than the willingness of the gpm core team to support each, plugins labeled as third party will be supported (or not) by their authors. Further Reading

The creator for the gpm-git and gpm-local wrote a fantastic blog post explaining the usage and rationale of gpm and gvp, it sums up explanations for several of the design decisions behind both tools. Contributing

Lots of people have contributed to make gpm what it is today, if you want to take your time to play around
with the code please do so! Opening issues on bugs, feature requests or simple food for thought are a great
way to contribute, if you send a pull request please be a good citizen and do things in a tidy manner. Create a feature branch with a meaningful name. Make sure your commit messages and PR comments are informative. Write a test for your feature if applicable. Always remember to run the test suite with make test before comitting.

Either way, thank you very much for any form of contribution, even if a patch ends up not being merged
the fact that it was sent and forced us to think about it is a contribution in itself.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.