Coder Social home page Coder Social logo

golang-seed's Introduction

golang-seed

Seed project for starting a dockerized, golang project. Features include:

Feel free to fork this repo to start your own project. The rest of the README below assumes you are using this as a template and will fill in extra details.

If you want to duplicate without forking see: https://help.github.com/articles/duplicating-a-repository

Structure

  • commands - add commands to execute/start your code in this package. You should not have to modify main.go. Read more about the library being used here: https://github.com/spf13/cobra.

  • config - package for managing configuration. Currently setup for dev, qa, prod environments. Defaults to dev. To set the environment, make sure an environment variable ENV is set on your target system.
    Configuration put in config-common.yml is accessible in all environments. To get a value from configuration do something like this after importing config package:

    myConfigurationValue := config.Viper.GetString("myConfigurationKey")
    

    See https://github.com/spf13/viper for more usage information.

  • logger - package to use for logging. Import this package and setup your own logger or use the root logger. e.g.

    // Root logger
    logger.Log.Info("This is using the root logger")
    
    // Child logger
    myPackageLogger := logger.Log.New("package", "myPackage", "someContextKey", "someContextValue")
    myPackageLogger.Info("This uses myPackageLogger which is a child of the root logger and shares root logger configuration.")
    

    See https://github.com/inconshreveable/log15 for more usage information.

Setup Instructions

Install Go (Windows)

Install chcolatey if you have not already done so (https://chocolatey.org/)

choco install golang

Install Go (Mac)

https://golang.org/doc/install

IDE

  • Install an IDE. Recommend Visual Studio Code
  • Create a directory for your go projects, ex: c:\source\go

Setting up Intellisense in Visual Studio Code (Mac/Windows)

Install go extension in visual studio code.

  • Open extensions window (cmd + shift + x)
  • Type go
  • Install the one with author of lukehoban.

Setting up Code directories

Assuming your workspace folder is c:\source\go, setup environment variable GOPATH = c:\source\go

Create bin, pkg, src sub-folders in $GOPATH.

Create $GOPATH\src\github.com\<your github username/organization> folder.

In the $GOPATH\src\github.com\<your github username/organization> folder, clone the repo. When finished you should have the folder: $GOPATH\src\github.com\<your github username/organization>\golang-seed

Packages

We use https://github.com/Masterminds/glide to manage package dependencies.

  1. Install glide and add it to your path. See https://github.com/Masterminds/glide#install
  2. Inside golang-seed directory run glide install --strip-vendor. This downloads all package dependencies to a vendor/ folder.
  3. If you need to add more dependencies to the project at any point run glide get <package name>, which will add the package to the glide.yaml. If you want to update dependencies to the latest version run glide up, this will update the glide.lock file with the latest dependencies.

Running tests

Golang has testing built in.

To run tests for a single package run:

go test ./<package name>

To run all tests run:

// Run all tests but skip vendor directory
go test $(glide novendor)

Automated deployments via Jenkins/Travis CI/etc

TODO fill in your deployment pipeline info here

To run locally

  • From root directory of project run
go install
  • To see what commands you can run:
golang-seed

Coding tips

Testing

  • Generate mocks using counterfeiter
go get github.com/maxbrunsfeld/counterfeiter

From project folder or inside package folder

go generate

Contributing code

Read this article and follow the steps they outline: http://scottchacon.com/2011/08/31/github-flow.html

All PRs should be signed off by a member of the team before merging.

Team

  • List
  • Your
  • Team
  • Members

Original release

February 2016

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.