Powered by Cookiecutter, Cookiecutter Golang is a framework for jumpstarting production-ready go projects quickly.
- Generous
Makefile
with management commands - Uses
go dep
(with optional go module support requires go 1.11) - injects build time and git hash at build time.
- Makefile support (soon)
- Can create dockerfile for building go binary and dockerfile for final go binary (no code in final container) (soon)
- If docker is used adds docker management commands to makefile (soon)
- Can use mysql or postgresql database provider
- Uses
dep
ormod
for dependency management - Only maintained 3rd party libraries are used.
This project now uses docker multistage builds, you need at least docker version v17.05.0-ce to use the docker file in this template, you can read more about multistage builds here.
This template uses docker multistage builds to make images slimmer and containers only the final project binary and assets with no source code whatsoever.
You can find the image dokcer file in this repo and more information about docker multistage builds in this blog post.
Apps run under non root user and also with dumb-init.
Let's pretend you want to create a project called "echoserver". Rather than starting from scratch maybe copying some files and then editing the results to include your name, email, and various configuration issues that always get forgotten until the worst possible moment, get cookiecutter to do all the work.
First, get Cookiecutter. Trust me, it's awesome:
$ pip install cookiecutter
Alternatively, you can install cookiecutter
with homebrew:
$ brew install cookiecutter
Finally, to run it based on this template, type:
$ cookiecutter https://github.com/lacion/cookiecutter-golang.git
You will be asked about your basic info (name, project name, app name, etc.). This info will be used to customize your new project.
Warning: After this point, change 'Luis Morales', 'lacion', etc to your own information.
Answer the prompts with your own desired options. For example:
full_name [Granger Doe]: Hansel
github_username [fdnetworks]: deneuv34
app_name [mygolangproject]: golang-api
Select database:
1 - mysql
2 - postgres
Choose from 1, 2 [1]: 1
project_short_description [A Golang project.]: Some description
Select use_git [y]: y
Enter the project and take a look around:
$ cd echoserver/
$ ls
Run make help
to see the available management commands, or just run make build
to build your project.
$ make help
$ make build
$ ./bin/echoserver
- iothub websocket multiroom server for IoT