Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Vendor Go dependencies

License

NotificationsYou must be signed in to change notification settings

owenthereal/nut

Repository files navigation

Gophers love nuts.

nut

nut is a tool that allows Go projects to declare dependencies, download dependencies, rewrite import paths and ensure that dependencies are properly vendored.

To accomplish this goal,nut does three things:

  • Introduces a metadata file with dependency information.
  • Fetches your project's dependencies and rewrite their import paths.
  • Introduces conventions for managing vendored dependencies.

nut is specifically designed to manage dependencies for a binary program. If you are making a library, please followthe standard Go way.

Voting fornut

I madenut as part of theGopher Gala contest.If you like what you see, pleasevote for it.

Installation

Make sure you have a working Go environment.See the install instructions.

To installnut, simply run:

$ go get github.com/jingweno/nut

Make sure yourPATH includes to the$GOPATH/bin directory so yourcommands can be easily used:

export PATH=$PATH:$GOPATH/bin

Creating A New Project

Inside yourGOPATH, run:

$ nut new hello_world

Let's checkout whatnut has generated for us:

$ cd hello_world$ tree ..├── .gitignore├── Nut.toml├── README.md└── main.go0 directories, 4 files

First let's check outNut.toml:

[application]name ="hello_world"version ="0.0.1"authors = ["Your Name <you@example.com>"]

This piece of application information is reserved for future usage.

Adding a dependency

It's quite simple to add a dependency. Simply add it to yourNut.toml file:

[dependencies]"github.com/octokit/go-octokit/octokit" ="""github.com/fhs/go-netrc/netrc" ="4422b68c9c"

The format of declaring a dependency isPACKAGE = COMMIT-ISH.PACKAGE is a valid package path that passes intogo get.COMMIT-ISH can be any tag, sha or branch.An emptyCOMMIT-ISH means the latest version of the dependency.

Downloading dependencies

Runnut install to download dependencies.nut puts dependencies tovendor/_nuts/.Let's take a look this folder:

$ tree vendorvendor└── _nuts    └── github.com        ├── fhs        │   └── go-netrc        │       ...        └── octokit            └── go-octokit                ...20 directories, 98 files

The import paths of all dependencies are rewritten to be relative tovendor/_nuts.For example, assuminggithub.com/octokit/go-octokit depends ongithub.com/sawyer/go-sawyer,all the import paths ofgo-octokit togo-sawyer will be relative tovendor/_nuts since they're vendored.

Importing a dependency

To import a dependency, refer to it by its full import path:

package mainimport ("github.com/jingweno/hello_world/vendor/_nuts/github.com/octokit/go-octokit/octokit")funcmain() {c:=octokit.NewClient()...}

Building

All dependencies are properly vendored tovendor/_nuts and your program is referring to import paths relative to this folder.go build andgo test should just work.

Demo

demo

FAQ

What makesnut different than other dependency management tools?

nut allows you to lock dependencies, vendor them and rewrite their import paths.The dependencies vendored bynut are "self contained" and are ready for use without overridingGOPATH.Most existing dependency management tools in Go overrideGOPATH and you need an extra tool to build your project.Withnut, you can build your project with justgo build.nut properly vendors dependencies so that existinggo commands work as a standard Go project.

Isnut the same asgodep save -r?

godep allow rewriting the import paths of dependencies withgodep save -r.nut does exactly the same thing in this regard.However,godep doesn't allow updating any dependency with rewritten import paths.nut doesn't currently support update of dependencies but it's a high priority item that will be implemented next.The workflow will be as straightforward asnut update FOO to update an individual dependency specified inNut.toml.

Besides,nut's design philosophy is very different fromgodep:nut is explicit about dependency management with a manifest file (Nut.toml) and allows locking of dependencies, whereasgodep isn't.

Who is usingnut?

Other arts

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp