A general purpose project template for golang CLI applications
This template serves as a starting point for golang commandline applications it is based on golang projects that I consider high quality and various other useful blog posts that helped me understanding golang better.
This template serves as a starting point for golang commandline applications it is based on golang projects that I consider high quality and various other useful blog posts that helped me understanding golang better.
- gitlabci-last-pipeline-run
- Features
- Project Layout
- How to use this template
- Demo Application
- Makefile Targets
- Contribute
- goreleaser with
deb.
and.rpm
packer and container (docker.hub
andghcr.io
) releasing includingmanpages
andshell completions
and grouped Changelog generation. - golangci-lint for linting and formatting
- Github Actions Stages (Lint, Test (
windows
,linux
,mac-os
), Build, Release) - Gitlab CI Configuration (Lint, Test, Build, Release)
- cobra example setup including tests
- Makefile - with various useful targets and documentation (see Makefile Targets)
- Github Pages using jekyll-theme-minimal (checkout https://MichaelPereira.github.io/gitlabci-last-pipeline-run/)
- Useful
README.md
badges - pre-commit-hooks for formatting and validating code before committing
- assets/ => docs, images, etc
- cmd/ => commandline configurartions (flags, subcommands)
- pkg/ => packages that are okay to import for other projects
- internal/ => packages that are only for project internal purposes
tools/
=> for automatically shipping all required dependencies when runninggo get
(ormake bootstrap
) such asgolang-ci-lint
(see: https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module) )scripts/
=> build scripts
bash <(curl -s https://raw.githubusercontent.com/MichaelPereira/gitlabci-last-pipeline-run/master/install.sh)
In order to make the CI work you will need to have the following Secrets in your repository defined:
Repository -> Settings -> Secrets & variables -> CODECOV_TOKEN
, DOCKERHUB_TOKEN
& DOCKERHUB_USERNAME
$> gitlabci-last-pipeline-run -h
golang-cli project template demo application
Usage:
gitlabci-last-pipeline-run [flags]
gitlabci-last-pipeline-run [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
example example subcommand which adds or multiplies two given integers
help Help about any command
version gitlabci-last-pipeline-run version
Flags:
-h, --help help for gitlabci-last-pipeline-run
Use "gitlabci-last-pipeline-run [command] --help" for more information about a command.
$> gitlabci-last-pipeline-run example 2 5 --add
7
$> gitlabci-last-pipeline-run example 2 5 --multiply
10
$> make
bootstrap install build deps
build build golang binary
clean clean up environment
cover display test coverage
docker-build dockerize golang application
fmt format go files
help list makefile targets
install install golang binary
lint lint go files
pre-commit run pre-commit hooks
run run the app
test display test coverage
If you find issues in that setup or have some nice features / improvements, I would welcome an issue or a PR :)