A template for golang web applications inspired by Ruby on Rails
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:
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.
*_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
READMEfiles to describe their purpose.
This guide assumes that you have a working Go environment, and Postgres running on port
createdb okgo_dev; createdb okgo_test
git clone [email protected]:runemadsen/ok-go.git github.com/runemadsen/ok-go
.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:
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-gopackages to your own repository name.
To run the development server, run
gulp serverand open
localhost:3000in your browser. Gin will recompile the app code on any changes to
.gofiles, but does currently not support watching
.htmltemplate files. Gulp will recompile the assets on any changes.
ginkgo -rfrom 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
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