Skip to content

Instantly share code, notes, and snippets.

@DanielHeath
Last active December 14, 2016 05:05
Show Gist options
  • Save DanielHeath/fca874047e9fc2c0ffddecc5676de9f0 to your computer and use it in GitHub Desktop.
Save DanielHeath/fca874047e9fc2c0ffddecc5676de9f0 to your computer and use it in GitHub Desktop.
Setting up a go project to produce a binary
export GOPATH="$(pwd):$(pwd)/vendor"
export PATH="$(pwd)/bin:$PATH"
export CDPATH=.:$(pwd)/src/github.com:$(pwd)/vendor/src/golang.org:$(pwd)/src
if [ -f .env.secret ] ; then
source .env.secret
fi

What is this

This setup is for a go project that produces a binary (it's not suitable for publishing a library). The first person to set it up needs gb installed globalally (see go get github.com/constabulary/gb/... ).

# Install GB globally:
go get github.com/constabulary/gb/...

# Start a git dir
git init .

# Create output directories
mkdir -p src vendor/src pkg bin

# Ignore temporary and secret files:
echo 'pkg' >> .gitignore
echo 'bin' >> .gitignore
echo '.env.secret' >> .gitignore

# Put the env and make files in place
wget -O Makefile "https://gist.githubusercontent.com/DanielHeath/fca874047e9fc2c0ffddecc5676de9f0/raw/a9c8af8f66d5d3d7bf493ef760524055aaa71501/Makefile"
wget -O .env "https://gist.githubusercontent.com/DanielHeath/fca874047e9fc2c0ffddecc5676de9f0/raw/a9c8af8f66d5d3d7bf493ef760524055aaa71501/.env"

# Use your global copy of gb to create a vendored copy of gb
gb vendor fetch github.com/constabulary/gb
make bin/gb

# Commit
git init .
git add .
git commit -m "Initial setup"

N.B.

When

#!/usr/bin/env make -f
export GOPATH := $(CURDIR):$(CURDIR)/vendor
export PATH := $(CURDIR)/bin:$(PATH)
.PHONY: devel ./bin/server
default: devel
test: $(wildcard src/**/*.go) $(wildcard vendor/src/**/*.go) ./bin/gb
gb test
bin/gb-vendor:
go build -o bin/gb-vendor github.com/constabulary/gb/cmd/gb-vendor
bin/gb: bin/gb-vendor
go build -o bin/gb github.com/constabulary/gb/cmd/gb
bin/% : $(wildcard src/**/*.go) $(wildcard vendor/src/**/*.go) ./bin/gb
gb build $( basename $@ )
doc:
godoc -http :6060
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment