GithubHelp home page GithubHelp logo

lacion / cookiecutter-golang Goto Github PK

View Code? Open in Web Editor NEW
673.0 9.0 174.0 42 KB

A Go project template

License: MIT License

Makefile 13.97% Go 52.19% Python 26.42% Dockerfile 7.43%
cookiecutter cookiecutter-golang golang project-template

cookiecutter-golang's Introduction

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

cookiecutter-golang's People

Contributors

adriangonz avatar benmezger avatar dependabot[bot] avatar gauthierc avatar jflbr avatar lacion avatar rasa avatar rizki96 avatar se77en avatar timmathews avatar zackijack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cookiecutter-golang's Issues

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

Module support

now that modules are officially here it may be good to have an option to create a module version of the template.

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

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

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?

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.

Pip?

Why use pip? go get does an install. Use Go to build Go tools. Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.