gb-vendor

gb-vendor is a simple gb plugin that wraps the go get command to make it easier to create your initial gb project.

Installation

gb-vendor is not included with gb. Installation is currently via go get

go get -u -v github.com/constabulary/gb-vendor

Usage

Simple Example

In this example we’ll create a gb project from the github.com/pkg/sftp codebase.

First, create a project:

% mkdir -p ~/devel/sftp
% cd ~/devel/sftp

Now checkout github.com/pkg/sftp to the path it expects:

% mkdir -p src/github.com/pkg/sftp
% git clone https://github.com/pkg/sftp src/github.com/pkg/sftp
% tree -d
.
└── src
    └── github.com
        └── pkg
            └── sftp
                └── examples
                    ├── buffered-read-benchmark
                    ├── buffered-write-benchmark
                    ├── gsftp
                    ├── streaming-read-benchmark
                    └── streaming-write-benchmark

Now, let’s try to build this:

% gb build all
FATAL command "build" failed: failed to resolve package "github.com/pkg/sftp": cannot find package "github.com/kr/fs" in any of:
       /home/dfc/go/src/github.com/kr/fs (from $GOROOT)
       /home/dfc/devel/sftp/src/github.com/kr/fs (from $GOPATH)
       /home/dfc/devel/sftp/vendor/src/github.com/kr/fs

The build failed because the dependency, github.com/kr/fs was not found in the project, which was expected (ignore the message about $GOPATH this is a side effect of reusing the go/build package for dependency resolution).

So we can use the gb vendor plugin to fetch the code for github.com/kr/fs:

% gb vendor github.com/kr/fs
% tree -d
.
├── src
│   └── github.com
│       └── pkg
│           └── sftp
│               └── examples
│                   ├── buffered-read-benchmark
│                   ├── buffered-write-benchmark
│                   ├── gsftp
│                   ├── streaming-read-benchmark
│                   └── streaming-write-benchmark
└── vendor
    └── src
        └── github.com
            └── kr
                └── fs

Now, let’s try to build this again:

% gb build all
FATAL command "build" failed: failed to resolve package "github.com/pkg/sftp": cannot find package "golang.org/x/crypto/ssh" in any of:
       /home/dfc/go/src/golang.org/x/crypto/ssh (from $GOROOT)
       /home/dfc/devel/sftp/src/golang.org/x/crypto/ssh (from $GOPATH)
       /home/dfc/devel/sftp/vendor/src/golang.org/x/crypto/ssh

Nearly, there, just missing the golang.org/x/crypto/ssh package, again we’ll use gb vendor.

% gb vendor golang.org/x/crypto/ssh
% tree -d
.
├── src
│   └── github.com
│       └── pkg
│           └── sftp
│               └── examples
│                   ├── buffered-read-benchmark
│                   ├── buffered-write-benchmark
│                   ├── gsftp
│                   ├── streaming-read-benchmark
│                   └── streaming-write-benchmark
└── vendor
    └── src
        ├── github.com
        │   └── kr
        │       └── fs
        └── golang.org
            └── x
                └── crypto
                    ├── bcrypt
                    ├── blowfish
                    ├── bn256
                    ...

Build the code one last time:

% gb build all
github.com/kr/fs
golang.org/x/crypto/ssh
golang.org/x/crypto/ssh/agent
github.com/pkg/sftp
github.com/pkg/sftp/examples/buffered-read-benchmark
github.com/pkg/sftp/examples/buffered-write-benchmark
github.com/pkg/sftp/examples/gsftp
github.com/pkg/sftp/examples/streaming-read-benchmark
github.com/pkg/sftp/examples/streaming-write-benchmark
% bin/buffered-read-benchmark
2015/05/13 20:39:54 reading 1e+09 bytes
2015/05/13 20:40:19 read 1000000000 bytes in 24.592188456s

Wrapping up

Setting up, or converting code to a gb project is simple. Once you’ve done this, you should check your $PROJECT directory into a source control. This includes any source you have vendored from other projects into your $PROJECT/vendor/src/ directory.