This is my personal GOLANG project template. It is built with these goals in mind:
-
Everything should be local to the development folder as much as is possible without resorting to ugly hacks.
-
1-step build or test without any special setup after any
git cloneon a newly minted machine except for installing thegocompiler itself. -
Do not rely on global
GOPATHand yet still allows you to check your entire source folder in as if you would a normal go program inside one. This makes your repository plays well with other go coders who will surely be using the globalGOPATHconvention.
Run this one-liner to dump the repository content into current directory.
curl -L https://github.com/chakrit/go-scratch/archive/master.tar.gz | tar -xzv --strip 1Do not forget to update the LICENSE file to match what you need. Or simply remove it.
Example for a full setup for a new project:
mkdir your-new-shiny-project # Make a new shiny folder for your new project.
cd your-new-shiny-project # Get into the folder first, of course.
git init # Or not, doesn't matter.
# Download the scratch template
curl -L https://github.com/chakrit/go-scratch/archive/master.tar.gz | tar -xzv --strip 1
# (optional) vim LICENSE # Edit LICENSE file.
git add .
git commit -m "Initialize GOLANG project. (github.com/chakrit/go-scratch)"Everything is done through the Makefile for convenience. A wrapper script ./go is also
provided that invokes go with GOPATH sets to the local .go folder.
Makefile tasks defaults to test. The all task is simply an alias for the build
task. All common tasks you'd do with go is given the same name in the Makefile so
go vet is, through the Makefile, make vet or via the wrapper script ./go vet.
Dependencies are handled implicitly and automatically as you run tasks that involve import
paths thanks to the powerful go get command.
Specifically, make deps and make test-deps will download the dependencies into place
and subsequent make test or make build will automaticaly compiles the downloaded
dependencies as needed.
The initial main.go file provided with this project contains some dependencies as well
as tests (and test dependencies) to demonstrate this.
This template supports multiple packages development inside a single folder out of the
box. You are, however, required to list all the subpackage paths inside the Makefile PKG
variable as automatically detecting them is tricky and error prone.
For example, if you have a context subpackage, edit the PKG line like so:
PKG := . ./context... or if you have nothing in the root folder and only subpackages uno dos and tres:
PKG := ./uno ./dos ./tresHere's a sample output of what happens when you simply cloned this repository and issue
make:
$ make
/Users/chakrit/Documents/go-scratch/go get -d -t .
/Users/chakrit/Documents/go-scratch/go test .
ok _/Users/chakrit/Documents/go-scratch0.010sUses make's -s flag to prevent make from echoing commands (useful for reducing
clutter to standard output.)
$ make -s
ok _/Users/chakrit/Documents/go-scratch 0.011s- Package the curl installation into a script.