Giter Site home page Giter Site logo

nut's Introduction

nut

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 follow the standard Go way.

Voting for nut

I made nut as part of the Gopher Gala contest. If you like what you see, please vote for it.

Installation

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

To install nut, simply run:

$ go get github.com/gophergala/nut

Make sure your PATH includes to the $GOPATH/bin directory so your commands can be easily used:

export PATH=$PATH:$GOPATH/bin

Creating A New Project

Inside your GOPATH, run:

$ nut new hello_world

Let's checkout what nut has generated for us:

$ cd hello_world
$ tree .
.
├── .gitignore
├── Nut.toml
├── README.md
└── main.go

0 directories, 4 files

First let's check out Nut.toml:

[application]

name = "hello_world"
version = "0.0.1"
authors = ["Your Name <[email protected]>"]

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 your Nut.toml file:

[dependencies]

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

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

Downloading dependencies

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

$ tree vendor
vendor
└── _nuts
    └── github.com
        ├── fhs
        │   └── go-netrc
        │       ...
        └── octokit
            └── go-octokit
                ...

20 directories, 98 files

The import paths of all dependencies are rewritten to be relative to vendor/_nuts. For example, assuming github.com/octokit/go-octokit depends on github.com/sawyer/go-sawyer, all the import paths of go-octokit to go-sawyer will be relative to vendor/_nuts since they're vendored.

Importing a dependency

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

package main

import (
  github.com/jingweno/hello_world/vendor/_nuts/github.com/octokit/go-octokit/octokit
)

func main() {
    c := octokit.NewClient()
    ...
}

Building

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

Demo

demo

FAQ

What makes nut different than other dependency management tools?

nut allows you to lock dependencies, vendor them and rewrite their import paths. The dependencies vendored by nut are "self contained" and are ready for use without overriding GOPATH. Most existing dependency management tools in Go override GOPATH and you need an extra tool to build your project. With nut, you can build your project with just go build. nut properly vendors dependencies so that existing go commands work as a standard Go project.

Is nut the same as godep save -r?

godep allow rewriting the import paths of dependencies with godep 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 as nut update FOO to update an individual dependency specified in Nut.toml.

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

Who is using nut?

Other arts

nut's People

Contributors

owenthereal avatar dvirsky avatar pmcatominey avatar

Watchers

Roey Berman avatar Arik Fraimovich avatar  avatar Joey Simhon avatar James Cloos avatar Eyal Biran avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.