Ok Go Web Template
A Golang web application template with most of the stuff you've come to enjoy from Ruby on Rails. For more information of why I built this, read the blog post. Pull requests are more than encouraged! I've tried to comment the code as much as possible.
The following features are a part of the template. You will probably end up using only a selected handful of them for your specific projects.
Routing with Gorilla Mux. You can replace this with your favorite Golang routing library if needed. This is your
controllersfolder in Rails.
Template rendering with Render. This is your
viewsfolder in Rails.
Asset pipeline with Gulp. Although not specifically a Golang setup, it generates digested
.scssassets, as well as a
manifest.jsonwith the file paths. A Golang
asset_pathhelper is available in the templates. Digested assets are disabled in development mode for ease of development.
Configuration is stored in the OS environment, with support for development (
.env) and test (
.env.test) environments with Godotenv.
Testing with Ginkgo and Gomega. Golang prefers the tests to live alongside the actual files, and will automatically ignore files named
*_test.goduring compilation. This template has both simple route tests and model tests, as well as some nice helper functions to access the HTTP responses like you know it from
All of the folders have
README files to describe their purpose.
This guide assumes that you have a working Go environment, and Postgres running on port
- Create your dev and test databases.
createdb okgo_dev; createdb okgo_test
- Clone this repo to your
git clone firstname.lastname@example.org:runemadsen/ok-go.git github.com/runemadsen/ok-go
- Create a
.envfile and a
.env.testfile in the new folder root. This will be the place to put environment specific variables. You only need one for now:
- Install all imported packages with
go get, and a few extra command-line requirements:
go get -u github.com/codegangsta/gin
go get -u github.com/chuckpreslar/gofer/gofer
sudo npm install -g gulp && npm install
That's it. If you start using this template for your own application, you might want to rename the
runemadsen/ok-go packages to your own repository name.
To run the development server, run
gulp server and open
localhost:3000 in your browser. Gin will recompile the app code on any changes to
.go files, but does currently not support watching
.html template files. Gulp will recompile the assets on any changes.
ginkgo -r from the root folder to run the tests.
This template is built to just work on Heroku. Right now, it requires you to commit the golang dependencies and precompiled assets to the Git repo.
heroku create -b https://github.com/kr/heroku-buildpack-go.git
- Add a database to your new heroku server.
heroku config:set GO_ENV=production
git add .; git commit -m 'adding compiled assets and dependencies'
git push heroku master
heroku run gofer db:migrate