by runemadsen

runemadsen / ok-go

A template for golang web applications inspired by Ruby on Rails

209 Stars 10 Forks Last release: Not found 74 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Ok Go Web Template

Ok Go

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.

  • Middleware support with Negroni. The template has a single custom middleware handler to serve as inspiration, but more can be added easily if needed.

  • Routing with Gorilla Mux. You can replace this with your favorite Golang routing library if needed. This is your

    folder in Rails.
  • Database ORM support with Gorm. The template ships with a simple Go struct and some basic CRUD routes.

  • Database migrations with Gomigrate and Gofer for easy command line syntax.

  • Template rendering with Render. This is your

    folder in Rails.
  • Asset pipeline with Gulp. Although not specifically a Golang setup, it generates digested

    assets, as well as a
    with the file paths. A Golang
    helper 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 (

    ) and 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

    during 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

Getting Started

All of the folders have

files to describe their purpose.


This guide assumes that you have a working Go environment, and Postgres running on port

  1. Create your dev and test databases.
    createdb okgo_dev; createdb okgo_test
  2. Clone this repo to your
    git clone [email protected]:runemadsen/ok-go.git github.com/runemadsen/ok-go
  3. Create a
    file and a
    file in the new folder root. This will be the place to put environment specific variables. You only need one for now:
    DATABASE_URL=postgres://[email protected]:5432/okgo_ENVIRONMENT?sslmode=disable
  4. 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

packages to your own repository name.

To run the development server, run

gulp server
and open
in your browser. Gin will recompile the app code on any changes to
files, but does currently not support watching
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.

  1. heroku create -b https://github.com/kr/heroku-buildpack-go.git
  2. Add a database to your new heroku server.
  3. heroku config:set GO_ENV=production
  4. godep save
  5. gulp assets:precompile
  6. git add .; git commit -m 'adding compiled assets and dependencies'
  7. git push heroku master
  8. heroku run gofer db:migrate

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.