Skip to content
This repository


Goliath provides a simple mechanism to share and load common configuration between different environments and even different web-services. To get started, simply create a config directory and provide a ruby configuration file with the same name as your API:

      |- echo.rb
      |- config/
        |- echo.rb

The config files themselves are Ruby code that will be evaluated when the server is starting. During this process, config and options variables are accessible from within your config file. Anything stored in the config will be available to all subsequent requests: shared connections, shared variables, and so on. The options hash represents the command line options provided to the API at startup.

As an example, in our echo.rb configuration file we could initialize a pool of asynchronous MySQL connections:

require 'em-synchrony/mysql2'

config['db'] = => 20) do => 'localhost', :username => 'test',
                             :password => 'password', :socket => nil,
                             :database => 'echo_db',
                             :reconnect => true)

Then, in the API server itself we can access one of the shared DB connections directly:

ret = db.query("SELECT COUNT(1) FROM some_table")


The running environment can be set in a number of ways. In order of increasing precedence:

  1. Default (:development)
  3. -e/--environment NAME flag from the command line
  4. Explicit call to Goliath#env=

You can customize your configuration based on the type of environment:

hostname = nil

environment :production do
    hostname = ''

environment :development do
    hostname = ''

environment :test do
    hostname = ''

Shared config data

Often, you will need or want to share the same configuration between multiple web-services. To do so, simply import the common configuration file:


# regular configuration ...

environment :production do
    # ...
Something went wrong with that request. Please try again.