Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0e014af52f
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (45 sloc) 1.784 kb
require 'bundler/setup'
Bundler.require(:default)
require 'goliath/plugins/latency'
#redis = Redis.new
#redis.select(12)
module AuthMan
extend self
def auth
Proc.new do |u, p|
u == 'admin' && p == 'matrix00'
end
end
end
class EchoLog < Goliath::API
#use ::Rack::Reloader, 0 if Goliath.dev?
use Rack::Auth::Basic, "Realm value", &AuthMan.auth
use Goliath::Rack::Params # parse & merge query and body parameters
use Goliath::Rack::DefaultMimeType # cleanup accepted media types
use Goliath::Rack::Formatters::JSON # JSON output formatter
use Goliath::Rack::Render # auto-negotiate response format
use Goliath::Rack::Heartbeat # respond to /status with 200, OK (monitoring, etc)
use Goliath::Rack::ValidationError # catch and render validation errors
#use Goliath::Rack::Validation::RequestMethod, %w(GET POST) # allow GET and POST requests only
#use Goliath::Rack::Validation::RequiredParam, {:key => 'echo'} # must provide ?echo= query or body param
#use Goliath::Rack::Validation::BooleanValue, {:key => 'bool', :default => true}
#plugin Goliath::Plugin::Latency
def process_request
logger.info "Processing request"
{response: env.params['echo'], params: env.params}
end
def response(env)
info = {timestamp: Time.now.to_i,
params: env.params,
method: env[Goliath::Request::REQUEST_METHOD],
path: env[Goliath::Request::REQUEST_PATH],
body: env[Goliath::Request::RACK_INPUT].read
}
json = MultiJson.encode(info)
logger.info "env: #{env.inspect}"
logger.info "logging: #{info.inspect}"
env.config['redis'].rpush("goliath:log", json)
#[200, {}, process_request]
[200, {}, info]
end
end
Jump to Line
Something went wrong with that request. Please try again.