A Go project general Makefile, encapsulated some common Target. Inspired by hgfischer/gomk
- Download
go.mk
to your project:
curl -O https://raw.githubusercontent.com/elliotxx/go-makefile/master/go.mk
include go.mk
in a new or existing Makefile;- add
coverage.out
to.gitignore
; - In the
Makefile
of your Go project, mark the available targets through##
,##
followed by the introduction of the target, and the targets marked through##
will be displayed in the help list:
In Makefile
:
hello: ## Echo hello message
echo "hello world"
In terminal
:
$ make
help This help message :)
hello Echo hello message
......
- Must be referenced in
Makefile
, you can't be other file names
APPROOT
: Name of the application, based on the repository name. Such askubernetes
.GOPKG
: Package name of the current go project. Such asgithub.com/elliotxx/go-makefile
.GOPKGS
: all Go pkgs inside the project repositoryGOSOURCES
: all.go
files inside the project repositoryGOSOURCE_PATHS
: Source code paths of the current go project. Such as./pkg/... ./cmd/...
.COVERAGEOUT
: Coverage of the current go project. Default tocoverage.out
.
NOTE: Please check if the preset variables of the go.mk
conflict with the variable names in your Makefile
If you want to give priority to the variable values in your Makefile
, you can use the following usage:
GOSOURCE_PATHS ?= ./pkg/... ./cmd/...
include go.mk
help
: Show yourMakefile
andgo.mk
. All available Targets and it`s profiletest
: Run all Go testscover
: Run all Go tests and generate coverage report file${COVERAGEOUT}
cover-html
: Display the visual results of the coverage report in the browserformat
: Format all Go fileslint
: Check all Go files using the Lint toollint-fix
: Lint, will try to fix errors and modify codedoc
: Start the documentation server with godoc