forked from thurloat/dough
parent
49b26be43e
commit
c23178c0f0
@ -1,26 +1,33 @@ |
||||
defmodule Dough.RequestContext do |
||||
require Logger |
||||
|
||||
|
||||
defstruct [:start, :close, :lookup, :cache, :ttl] |
||||
|
||||
def ctx_start(ctx) do |
||||
|
||||
def ctx_start(ctx) do |
||||
Map.put(ctx, :start, System.monotonic_time(:milliseconds)) |
||||
end |
||||
|
||||
def ctx_close(ctx) do |
||||
Map.put(ctx, :close, System.monotonic_time(:milliseconds)) |
||||
end |
||||
|
||||
def ctx_lookup(ctx, dns_record) do |
||||
Map.put(ctx, :lookup, dns_record.qdlist |> List.first()) |
||||
end |
||||
|
||||
def ctx_cachehit(ctx, v) do |
||||
Map.put(ctx, :cache, v) |
||||
end |
||||
|
||||
def ctx_ttl(ctx, ttl) do |
||||
Map.put(ctx, :ttl, ttl) |
||||
end |
||||
|
||||
def ctx_log_out(ctx) do |
||||
Logger.info "#{ctx.lookup.type} - #{ctx.lookup.domain} - TTL #{ctx.ttl} | #{ctx.cache} - #{ctx.close - ctx.start}ms" |
||||
Logger.info( |
||||
"#{ctx.lookup.type} - #{ctx.lookup.domain} - TTL #{ctx.ttl} | #{ctx.cache} - #{ |
||||
ctx.close - ctx.start |
||||
}ms" |
||||
) |
||||
end |
||||
end |
||||
|
@ -1,13 +1,13 @@ |
||||
defmodule Dough.NotAllowed do |
||||
defexception [plug_status: 405, message: "Method Not Allowed"] |
||||
defexception plug_status: 405, message: "Method Not Allowed" |
||||
end |
||||
|
||||
defmodule Dough.ServerError do |
||||
defexception [plug_status: 500, message: "Server Error"] |
||||
defexception plug_status: 500, message: "Server Error" |
||||
end |
||||
|
||||
defimpl Plug.Exception, for: [Dough.NotAllowed, Dough.ServerError] do |
||||
def status(exc) do |
||||
exc.plug_status |
||||
def status(exc) do |
||||
exc.plug_status |
||||
end |
||||
end |
||||
|
Loading…
Reference in new issue