Cookie Cutting - Go project initialisation
Recently I seem to be spending an inordinate amount of time setting up project infrastructure for Go based projects. Looking at options around how I could template this activity I came across cookiecutter.
A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python package project template.
There are a huge amount of cookiecutters available on Github, you can search as follows: https://github.com/search?q=cookiecutter&type=Repositories
Cookiecutter takes a source directory tree and copies it into your new project. It replaces all the names that it finds surrounded by templating tags {{ and }} with names that it finds in the file cookiecutter.json. That’s basically it.
I’ve created a cc for golang projects, its available here https://github.com/damianoneill/cookiecutter-golang assuming you have cookiecutter installed, you can use this as follows:
cookiecutter gh:damianoneill/cookiecutter-golang
You will be prompted for a few project specific details and this will generate a new directory with a go project setup.
The project will provide the following functionality:
- Makefile – can be used to add project specific targets or to override/extend common targets
- golang.mk – contains common go targets
- go.mod
- tools.go – contains go tools used by this project, can be generated using make tools.
- cobra/viper based mainline
- cobra completion command
- cobra version command
- goreleaser config
- cross compiled bins
- docker image generation
- gitlab-ci config