-
Notifications
You must be signed in to change notification settings - Fork 0
/
helloworldzip.rb
47 lines (37 loc) · 1.23 KB
/
helloworldzip.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'sinatra'
require 'pg'
set :port, 4000
set :bind, '0.0.0.0'
get '/' do
begin
# Initialize connection variables.
host = String('75.72.238.228')
database = String('demoapp')
user = String('demoapp')
password = String('demopass')
# Initialize connection object.
connection = PG::Connection.new(:host => host, :user => user, :dbname => database, :port => '5432', :password => password)
puts 'Successfully created connection to database.'
resultSet = connection.exec('SELECT * from demotable;')
outStr = "<table><tr><th>id</th><th>name</th></tr>"
resultSet.each do |row|
puts 'Data row = (%s, %s)' % [row['id'], row['name']]
row_data = "<tr><td>#{row['id']}</td><td>#{row['name']}}</td></tr>"
outStr += "#{row_data}"
end
outStr += "</table>"
outStr
rescue PG::Error => e
puts e.message
ensure
connection.close if connection
end
end
require 'rack'
require 'zipkin-tracer'
ZIPKIN_TRACER_CONFIG = {
service_name: 'FBSampleApp',
sample_rate: 1.0,
json_api_host: ENV["ZIPKIN_URL"]
}.freeze
use ZipkinTracer::RackHandler, ZIPKIN_TRACER_CONFIG