Reducing Boiler Plate for Go Programs

As we deploy more and more go programs we noticed a lot of boiler plate code showing up. Also being mainly rails developers we like to have different environments for development, testing and production. Another requirement is the configuration of any database connection through a database.yml.

Enter adeven/go_conf

To address the issues mentioned and to make setting up a new go program easier i build this package.

what does it do?

  • use rails style config/database.yml
  • default write log. to log/server.log
  • enable usage of GO_ENV similiar to RAILS_ENV
  • provide many useful startup flags [config, log, etc.]

how to use it?

Very easy, just install with

go get github.com/adeven/go_conf

and import it

1
import github.com/adeven/go_conf

and then just use it

1
2
redis_host, redis_db := go_conf.GetRedisConf()
...

your config/database.yml would look something like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
redis_development:
  host: localhost
  db: 1

redis_test:
  host: localhost
  db: 1

redis_staging:
  host: localhost
  db: 1

redis_production:
  host: localhost
  db: 1

Now you can start you program like

go run main.go --config confg/mydb.yml --log log/development.log

I hope this package is as useful to you as it is to us.

Have fun.

Comments