Skip to content

Instantly share code, notes, and snippets.

@munjalpatel
Last active November 4, 2017 16:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save munjalpatel/0f05fb84c210c2f3ae3f22daada769c1 to your computer and use it in GitHub Desktop.
require "router"
require "msgpack"
require "./service-discovery-reader/*"
module Service::Discovery::Reader
class WebServer
include Router
@Services = {
"svc-a" => { "hostname" => "10.0.0.10", "port" => 4000_u16 },
"svc-b" => { "hostname" => "10.0.0.20", "port" => 4001_u16 },
"svc-c" => { "hostname" => "10.0.0.30", "port" => 4002_u16 },
"svc-d" => { "hostname" => "10.0.0.40", "port" => 4003_u16 },
"svc-e" => { "hostname" => "10.0.0.50", "port" => 4004_u16 },
"svc-f" => { "hostname" => "10.0.0.60", "port" => 4005_u16 },
}
@route_handler = RouteHandler.new
@index = API.new do |context|
context # returning context
end
@get_services = API.new do |context, params|
result = Hash(String, Hash(String, UInt16 | String) | Nil).new
params["list"].split(",") do |s|
result[s] = @Services[s]?
end
context.response.print result.to_msgpack
context
end
def initialize
draw(@route_handler) do
get "/", @index
get "/services/:list", @get_services
end
end
def run
server = HTTP::Server.new(4000, @route_handler)
server.listen
end
end
web_server = WebServer.new
puts "Listening on http://0.0.0.0:4000"
web_server.run
end
------
Invalid memory access (signal 11) at address 0x0
[0x10b52b2e2] __crystal_sigfault_handler +66
[0x7fffcef21b3a] _sigtramp +26
[0x10cc8dc33] _ZN4llvm11PointerType3getEPNS_4TypeEj +21
[0x10cc1b1e3] _ZN4llvm12ConstantExpr16getGetElementPtrEPNS_4TypeEPNS_8ConstantENS_8ArrayRefIPNS_5ValueEEEbNS_8OptionalIjEES2_ +193
[0x10c37f234] _ZN4llvm12ConstantExpr24getInBoundsGetElementPtrEPNS_4TypeEPNS_8ConstantENS_8ArrayRefIPNS_5ValueEEE +36
[0x10c75ddf4] _ZN4llvm9IRBuilderINS_14ConstantFolderENS_24IRBuilderDefaultInserterEE17CreateInBoundsGEPEPNS_4TypeEPNS_5ValueENS_8ArrayRefIS7_
EERKNS_5TwineE +84
[0x10cc29bd0] LLVMBuildInBoundsGEP +55
[0x10bc5e080] *Crystal::CodeGenVisitor@Crystal::LLVMBuilderHelper#gep<LLVM::Value, Int32, Int32, String>:LLVM::Value +176
[0x10bca6094] *Crystal::CodeGenVisitor#read_instance_var<Crystal::Type+, Crystal::Type+, String, LLVM::Value>:Bool +100
[0x10bc801b2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +19250
[0x10bca19c6] *Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool) +118
[0x10bc9c0df] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4767
[0x10bc7fcd8] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +18008
[0x10bca1d24] *Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool) +980
[0x10bc9c0df] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +4767
[0x10bc7fcd8] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +18008
[0x10bc8106c] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +23020
[0x10bc7cf30] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +6320
[0x10bc7e703] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +12419
[0x10bc7c489] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +3593
[0x10bc9c8c9] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +6793
[0x10bc7fcd8] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +18008
[0x10bc7c489] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +3593
[0x10bc8f4f9] *Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function +4377
[0x10bc7ccb0] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +5680
[0x10bcb13d4] *Crystal::CodeGenVisitor#run_instance_vars_initializers<Crystal::Type+, (Crystal::ClassType+ | Crystal::GenericClassType+), LLVM::Value>:Nil +1012
[0x10bcb073d] *Crystal::CodeGenVisitor#allocate_aggregate<Crystal::Type+>:LLVM::Value +3805
[0x10bca69c0] *Crystal::CodeGenVisitor#codegen_primitive<Crystal::Call, Crystal::Primitive+, Crystal::Def+, Array(LLVM::Value)>:LLVM::Value +1696
[0x10bc9c966] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +6950
[0x10bc7fcd8] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +18008
[0x10bc95595] *Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil) +277
[0x10bc7c9d6] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +4950
[0x10bc7c489] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +3593
[0x10bc8f4f9] *Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function +4377
[0x10bc932d6] *Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function +2742
[0x10bc9c983] *Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool +6979
[0x10bc7fcd8] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +18008
[0x10bc95595] *Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil) +277
[0x10bc7c9d6] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +4950
[0x10bc7c489] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +3593
[0x10bc7ba81] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +1025
[0x10bc7c489] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil +3593
[0x10bc38b00] *Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil) +512
[0x10bf9b074] *Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result +116
[0x10c00a7ce] *Crystal::Command#run_command<Bool>:Nil +158
[0x10b55635d] *Crystal::Command#run:(Bool | Crystal::Compiler::Result | IO::FileDescriptor | Nil) +13981
[0x10b52aa86] main +13414
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment