Thanks @yuyichao
Here are the relevant bits:
const _routes = Dict{Symbol,Any}()
const Route = Tuple{Tuple{String,String,Union{String,Function}},Dict{Symbol,Dict{Any,Any}}}
function route(action::Function, path::String; method = GET, with::Dict = Dict{Symbol,Any}(), named::Symbol = :__anonymous_route) :: Route
route(path, action, method = method, with = with, named = named)
end
function route(path::String, action::Union{String,Function}; method = GET, with::Dict = Dict{Symbol,Any}(), named::Symbol = :__anonymous_route) :: Route
route_parts = (method, path, action)
extra_route_parts = Dict(:with => with)
named = named == :__anonymous_route ? route_name(route_parts) : named
_routes[named] = (route_parts, extra_route_parts)
end
function routes() :: Vector{Route}
collect(values(_routes))
end
function match_routes(req::Request, res::Response, session::Sessions.Session, params::Params) :: Response
for r in routes()
route_def, extra_params = r
protocol, route, to = route_def
# more code in here that doesn't matter
return try
if isa(to, Function)
to() |> to_response
end
catch ex
Logger.log("Failed invoking controller", :err)
Logger.log(string(ex), :err)
Logger.log("$(@__FILE__):$(@__LINE__)", :err)
rethrow(ex)
end
end
serve_error_file(404, "Not found")
end
And the error:
2017-06-26T14:33:46.329 - critical: MethodError(#17, (), 0x0000000000005992)
2017-06-26T14:33:46.631 - critical:
Stacktrace:
[1] match_routes(::HttpCommon.Request, ::HttpCommon.Response, ::Sessions.Session, ::Router.Params{Any}) at /Users/adrian/.julia/v0.6/Genie/src/Router.jl:461
[2] route_request(::HttpCommon.Request, ::HttpCommon.Response, ::IPv4) at /Users/adrian/.julia/v0.6/Genie/src/Router.jl:86
[3] handle_request(::HttpCommon.Request, ::HttpCommon.Response, ::IPv4) at /Users/adrian/.julia/v0.6/Genie/src/AppServer.jl:122
[4] (::AppServer.##1#9)(::HttpCommon.Request, ::HttpCommon.Response) at /Users/adrian/.julia/v0.6/Genie/src/AppServer.jl:25
[5] (::HttpServer.#on_message_complete#14{HttpServer.Server,HttpServer.Client{TCPSocket},Bool})(::HttpCommon.Request) at /Users/adrian/.julia/v0.6/HttpServer/src/HttpServer.jl:427
[6] on_message_complete(::Ptr{HttpParser.Parser}) at /Users/adrian/.julia/v0.6/HttpServer/src/RequestParser.jl:113
[7] http_parser_execute(::HttpParser.Parser, ::HttpParser.ParserSettings, ::Array{UInt8,1}) at /Users/adrian/.julia/v0.6/HttpParser/src/HttpParser.jl:115
[8] process_client(::HttpServer.Server, ::HttpServer.Client{TCPSocket}, ::Bool) at /Users/adrian/.julia/v0.6/HttpServer/src/HttpServer.jl:389
[9] (::HttpServer.##7#8{HttpServer.Server,Bool})() at ./task.jl:335