Seed project for starting a dockerized, golang project. Features include:
- Command parsing with https://github.com/spf13/cobra
- Logging setup with https://github.com/inconshreveable/log15
- Configuration management with https://github.com/spf13/viper
- Dependency management and vendoring with https://github.com/Masterminds/glide
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
-
commands- add commands to execute/start your code in this package. You should not have to modifymain.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 variableENVis set on your target system.
Configuration put inconfig-common.ymlis accessible in all environments. To get a value from configuration do something like this after importingconfigpackage: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.
Install chcolatey if you have not already done so (https://chocolatey.org/)
choco install golang
https://golang.org/doc/install
Install an IDE. Recommend Atom https://atom.io
Install go-plus package https://github.com/joefitzgerald/go-plus
If Intellisense isn't working, try the following
gocode close
gocode -s -debug
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
We use https://github.com/Masterminds/glide to manage package dependencies.
- Install glide and add it to your path. See https://github.com/Masterminds/glide#install
- Inside
golang-seeddirectory runglide install --strip-vendor. This downloads all package dependencies to avendor/folder. - If you need to add more dependencies to the project at any point run
glide get <package name>, which will add the package to theglide.yaml. If you want to update dependencies to the latest version runglide up, this will update theglide.lockfile with the latest dependencies.
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)
TODO fill in your deployment pipeline info here
- From root directory of project run
go install
- To see what commands you can run:
golang-seed
Generate mocks using https://github.com/vektra/mockery
go get github.com/vektra/mockery/.../
$GOPATH/bin/mockery -name <interface name> -recursive
If you need to generate mocks in the same package to avoid circular dependencies use
$GOPATH/bin/mockery -name <interface name> -recursive -inpkg
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.
- List
- Your
- Team
- Members
February 2016