A Go project template

Overview

cookiecutter-golang

Build Status

Powered by Cookiecutter, Cookiecutter Golang is a framework for jumpstarting production-ready go projects quickly.

Features

  • 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.

Optional Integrations

  • Can use viper for env var config
  • Can use cobra for cli tools
  • Can use logrus for logging
  • Can create dockerfile for building go binary and dockerfile for final go binary (no code in final container)
  • If docker is used adds docker management commands to makefile
  • Option of TravisCI, CircleCI or None

Constraints

  • Uses dep or mod 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.

Docker

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.

Usage

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 [Luis Morales]: Luis Morales
github_username [lacion]: lacion
app_name [mygolangproject]: echoserver
project_short_description [A Golang project.]: Awesome Echo Server
docker_hub_username [lacion]: lacion
docker_image [lacion/docker-alpine:latest]: lacion/docker-alpine:latest
docker_build_image [lacion/docker-alpine:gobuildimage]: lacion/docker-alpine:gobuildimage
use_docker [y]: y
use_git [y]: y
use_logrus_logging [y]: y
use_viper_config [y]: y
use_cobra_cmd [y]: y
Select use_ci:
1 - travis
2 - circle
3 - none
Choose from 1, 2, 3 [1]: 1

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

Projects build with cookiecutter-golang

  • iothub websocket multiroom server for IoT
Comments
  • Update Dockerfile to correct build issues

    Update Dockerfile to correct build issues

    Running make package I ran into an error:

    GOPATH=/gopath
    go build -ldflags '-w -linkmode external -extldflags "-static" -X main.GitCommit=844219fde13bf43b1d592498393589445618b232 -X main.VersionPrerelease=VersionPrerelease=RC' -o bin/ark-watchman
    go: cannot find GOROOT directory: /usr/lib/go
    make: *** [Makefile:37: build-alpine] Error 2
    

    Running go env in the container I found GOROOT to be /usr/local/go not /usr/lib/go.

    opened by jrnt30 2
  • Replace import from example project

    Replace import from example project

    Describe the bug After creating a Go project, the version package import on cmd/version.go points to github.com/lacion/cookiecutter_golang_example/version, which I assume is the example project.

    To Reproduce

    1. Run cookiecutter https://github.com/lacion/cookiecutter-golang.git
    2. Select use_cobra_cmd [y]: y
    3. Go to the generated cmd/version.go

    Expected behavior Instead of github.com/lacion/cookiecutter_golang_example/version, cmd/version.go should import the generated github.com/<github_username>/<app_name>/version.

    Desktop (please complete the following information):

    • OS: Arch Linux
    • Golang Version go1.13.5

    Additional context This was using the latest version of the golang template.

    opened by adriangonz 1
  • Instructions to avoid Cobra and CircleCI ignored?

    Instructions to avoid Cobra and CircleCI ignored?

    Describe the bug My answers to the prompts:

    use_logrus_logging [y]: n
    use_viper_config [y]: 
    use_cobra_cmd [y]: n
    Select use_ci:
    1 - travis
    2 - circle
    3 - none
    Choose from 1, 2, 3 (1, 2, 3) [1]: 3
    

    However I still get those packages and directories:

    $ cat go.mod 
    module github.com/redthor/symbol-svc
    
    require (
            github.com/sirupsen/logrus v1.4.1
            github.com/spf13/cobra v0.0.3
            github.com/spf13/viper v1.3.2
    )
    
    $ ll .circleci/
    total 12
    drwxrwxr-x 2 douglas douglas 4096 Jun 20 23:32 ./
    drwxrwxr-x 6 douglas douglas 4096 Jun 20 23:32 ../
    -rw-rw-r-- 1 douglas douglas 1429 Jun 20 23:32 config.yml
    

    To Reproduce Steps to reproduce the behavior:

    1. Run cookiecutter https://github.com/lacion/cookiecutter-golang.git
    2. Answer as above

    Expected behavior I didn't expect to have the packages/directories relating to the options I've avoided.

    Desktop (please complete the following information):

    • OS: Ubuntu 18.04
    • Golang Version 1.12

    Thanks

    opened by redthor 1
  • why does

    why does "remove dep/mod" run after "git init" isn't the opposite?

    Is there any reason to put git init before removing mod/dep? because like the comment you wrote: "Initialize Git (should be run after all file have been modified or deleted)"

    if this is a bug, I have made this pull request #22 to fix it

    opened by zackijack 1
  • make missing from gobuildimage

    make missing from gobuildimage

    Starting a vanilla cookiecutter-golang project $ make build

    building gocrawler 0.1.0
    GOPATH=/Users/pauljones/go
    go build -ldflags "-X main.GitCommit=73b256979f7a3556c34009bd533d84e6bde743d6+CHANGES -X main.VersionPrerelease=DEV" -o bin/gocrawler
    

    $ make package

    Step 8/19 : RUN make build-alpine
     ---> Running in be127c896693
    /bin/sh: make: not found
    The command '/bin/sh -c make build-alpine' returned a non-zero code: 127
    

    Looking in the Dockerfile is make installed in the build container?

    question 
    opened by paulwilljones 1
  • CircleCI fails with default template: go: Command not found

    CircleCI fails with default template: go: Command not found

    Describe the bug When using the default setup, Docker and CircleCI.

    Setting the project up on CircleCI fails on the Run tests step with error:

    go test ./...
    make: go: Command not found
    make: *** [Makefile:60: test] Error 127
    
    Exited with code exit status 2
    

    To Reproduce Steps to reproduce the behavior:

    1. use cookie cutter with this template
    2. select all the defaults BUT chose CircleCI
    3. Push repo to github
    4. Setup as project on CircleCI
    5. add DOCKER_USER & DOCKER_PASS as env vars
    6. Notice it fails on Run tests step

    Expected behavior Should not fail on step 6 but pass

    Desktop (please complete the following information):

    • OS: OSX 10.15.3
    • Golang Version go1.14.2 darwin/amd64
    bug 
    opened by Joel-Valentine 0
  • Move Initialize Git method to last

    Move Initialize Git method to last

    Like the comment you wrote: Initialize Git (should be run after all file have been modified or deleted) but now the mod/dep file is still deleted after git init.

    This pull request only switch positions between git init with delete mod/dep method, so git is clean after the project is generated.

    opened by zackijack 0
  • Add ZeroLog as an option

    Add ZeroLog as an option

    I been using logrus for a long time now without really checking out alternatives, https://github.com/rs/zerolog seems like a lightweight logger that has what logrus and it may be a good alternative.

    help wanted 
    opened by lacion 0
  • Bump cookiecutter from 1.5.0 to 2.1.1

    Bump cookiecutter from 1.5.0 to 2.1.1

    Bumps cookiecutter from 1.5.0 to 2.1.1.

    Release notes

    Sourced from cookiecutter's releases.

    2.1.1

    Documentation updates

    Bugfixes

    • Sanitize Mercurial branch information before checkout. (#1689) @​ericof

    This release is made by wonderful contributors:

    @​alkatar21, @​ericof and @​jensens

    2.1.0

    Preamble

    This release log lists all changes from 1.7.3 to this release. It includes the log of the 2.0.x releases, which were never published on PyPI. Because of that it might look a bit blurry.

    We release the current stable state of the project, knowing there are a bunch of open pull requests. Those will be reviewed by the core-committers and merged or dropped.

    Future releases will happen more frequently. Stay tuned.

    Fetch fresh from PyPI https://pypi.org/project/cookiecutter/2.1.0/

    Changes

    Breaking Changes

    Minor Changes

    ... (truncated)

    Changelog

    Sourced from cookiecutter's changelog.

    2.1.1 (2022-06-01)

    Documentation updates

    Bugfixes

    • Sanitize Mercurial branch information before checkout. (#1689) @​ericof

    This release is made by wonderfull contributors:

    @​alkatar21, @​ericof and @​jensens

    2.1.0 (2022-05-30)

    Changes

    CI/CD and QA changes

    Documentation updates

    Bugfixes

    This release was made possible by our wonderful contributors:

    @​doobrie, @​jensens, @​ericof, @​luzfcb

    2.0.2 (2021-12-27)

    Remark: This release never made it to official PyPI

    ... (truncated)

    Commits
    • f9376a9 Prepare release 2.1.1
    • fdffddb Merge pull request #1689 from cookiecutter/sanitize-mercurial-checkout
    • 85a7884 Lint fixes
    • e26c465 Sanitize Mercurial branch information before checkout.
    • 94036d0 Merge pull request #1687 from cookiecutter/bump-version-back-to-dev
    • 70b2ee2 Merge pull request #1686 from alkatar21/patch-1
    • 8b33e96 Bump version to 2.1.1.dev0
    • 58d716f [Docs] Fix local extensions documentation
    • f601b71 Merge pull request #1684 from cookiecutter/bump-release-2.1.0
    • 96c6826 bump version and edit historie
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Add template to cookietemple

    Add template to cookietemple

    Hi,

    based on the structure that this template already has, would you be interested in adding your template to cookietemple? It certainly would be a nice addition.

    Cheers

    opened by Zethson 0
Owner
Luis Morales
I am a Site Reliability Engineer speaking, writing, consulting, I worked on a bunch of web sites you haven’t heard of.
Luis Morales
Moby Project - a collaborative project for the container ecosystem to assemble container-based systems

The Moby Project Moby is an open-source project created by Docker to enable and accelerate software containerization. It provides a "Lego set" of tool

Moby 64.8k Jan 2, 2023
Placeholder for the future project (lets-go-chat)Placeholder for the future project (lets-go-chat)

Placeholder for the future project (lets-go-chat)Placeholder for the future project (lets-go-chat)

null 0 Jan 10, 2022
A go backend you can use as a template

Golang project template form Golang Sri Lanka

Golang Sri Lanka 7 May 18, 2022
Template Repository For Bug Reporting

Template Repository For Bug Reporting Create a Repository From the Template First and foremost, create a repository from this template repository (the

Ent Foundation 11 Jun 25, 2022
Golang Github Template Helper

ggth Golang Github Template Helper Usage ggth PreBuilt Binaries Grab Binaries from The Releases Page Install Homebrew brew install Jmainguy/tap/ggth

Jonathan Mainguy 2 Jan 4, 2022
Orkestra Workflow Executor Template Repo

Orkestra Workflow Executor Template Repo This is a template repository for a new workflow executor Usage Generate your repository from this template b

Nitish Malhotra 0 Nov 9, 2021
The template repository is used for creating secondary sources written in Golang.

Source Template The template repository is used for creating secondary sources written in Golang. Getting Started Follow this getting started guide to

null 0 Dec 28, 2021
A template for using Mint Lang with Wails

wails-mint-template ?? UNDER CONSTRUCTION About A basic template that allows you to develop a Wails application using Mint Lang, a Crystal-powered pro

Marcus Crane 1 Dec 29, 2021
Works with HashiCorp HCL. Allows to append the input file with blocks and attributes from the template file

About hclmergetool Works with HashiCorp HCL. Allows to append the input file with blocks and attributes from the template file Installation Binary Rel

Max Fedorov 0 Feb 6, 2022
Knit is an inline code generation tool that combines the power of Go's text/template package with automatic spec file loading.

Knit Knit is an inline code generation tool that combines the power of Go's text/template package with automatic spec file loading. Example openapi: "

Tyler 4 Sep 15, 2022
GoLang Library for Browser Capabilities Project

Browser Capabilities GoLang Project PHP has get_browser() function which tells what the user's browser is capable of. You can check original documenta

Maksim N. 43 Sep 27, 2022
:guardsman: A teeny tiny and somewhat opinionated generator for your next golang project

A Yeoman Golang Generator We are very sorry Gophers, but other names for the generator where taken, so we choose go-lang. But we have gocreate as an a

Axel Springer SE 25 Sep 27, 2022
Example programs for the Gio project.

Gio Examples Example programs for the Gio project. Issues File bugs and TODOs through the issue tracker or send an email to ~eliasnaur/[email protected]

Gio 82 Dec 20, 2022
Standard Go Project Layout

This is a basic layout for Go application projects. It's not an official standard defined by the core Go dev team; however, it is a set of common historical and emerging project layout patterns in the Go ecosystem. Some of these patterns are more popular than others. It also has a number of small enhancements along with several supporting directories common to any large enough real world application.

null 36.8k Jan 3, 2023
bytecamp 2021 project

Calldiff 背景 复杂项目的日常迭代中,研发同学想了解某个改动的影响点,往往需要深入代码细节才能获得尽可能全的 checklist 。然而,由于项目的复杂性,我们获得的 checklist 又难免会有一些遗漏。 为了减轻研发同学的心智负担,辅助同学们更有效地保证服务稳定性,本项目应运而生。 本

null 3 Oct 4, 2021
This is an example of the cobra project

Devops cmd and mian.go This is an example of the cobra project Execute the following command in the current path to compile the project,you will appea

flyone 5 Sep 6, 2022
feedme project porting in Go language

newsapi-go This project has the intent to provide a valid interface for newsapi (https://newsapi.org/). usage The project is still under mantainance a

Fulvio 5 Oct 28, 2021
This is a simple project for demonstrating Temporal with the Go SDK.

This is a simple project for demonstrating Temporal with the Go SDK.

null 0 Oct 11, 2021
Small proof of concept project to try temporal.io with Dispatch Incident Management from Netflix.

temporal-dispatch-poc Small POC project to try out the Temporal workflow engine together with Netflix's Dispatch Incident Management System. Supported

Jørgen 1 Nov 12, 2021