mirror of https://github.com/mitchell/shortnr.git
Refactor dets repo, dockerfile, and url type; add logger level func
This commit is contained in:
parent
faaf12ba42
commit
fe413d2a5e
|
@ -1,6 +1,6 @@
|
||||||
FROM elixir:1.9-slim as build
|
FROM elixir:1.9-slim as build
|
||||||
|
|
||||||
WORKDIR /root/shortnr/service
|
WORKDIR /root/shortnr
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN mix local.hex --force
|
RUN mix local.hex --force
|
||||||
|
@ -11,7 +11,7 @@ RUN env MIX_ENV=prod mix release
|
||||||
FROM debian:buster-20191014-slim
|
FROM debian:buster-20191014-slim
|
||||||
|
|
||||||
WORKDIR /home/shortnr
|
WORKDIR /home/shortnr
|
||||||
COPY --from=build /root/shortnr/service/_build/prod/rel/service/ .
|
COPY --from=build /root/shortnr/_build/prod/rel/service/ .
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
libtinfo5=6.1+20181013-2+deb10u2 \
|
libtinfo5=6.1+20181013-2+deb10u2 \
|
||||||
|
|
|
@ -5,4 +5,9 @@ config :service,
|
||||||
|
|
||||||
config :logger, :console,
|
config :logger, :console,
|
||||||
format: "date=$date time=$time level=$level$levelpad message=\"$message\" $metadata\n",
|
format: "date=$date time=$time level=$level$levelpad message=\"$message\" $metadata\n",
|
||||||
metadata: [:port, :file, :line, :crash_reason, :stack]
|
metadata: [:port, :file, :line, :crash_reason, :stack],
|
||||||
|
level:
|
||||||
|
(fn
|
||||||
|
:prod -> :info
|
||||||
|
_ -> :debug
|
||||||
|
end).(Mix.env())
|
||||||
|
|
|
@ -46,7 +46,7 @@ defmodule Shortnr.Router do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_errors(conn, %{kind: _kind, reason: reason, stack: stack}) do
|
def handle_errors(conn, %{kind: _kind, reason: reason, stack: stack}) do
|
||||||
Logger.error(inspect(reason), stack: inspect(stack))
|
Logger.error(reason, stack: stack)
|
||||||
|
|
||||||
{:error, {:internal_server_error, "internal server error"}, conn}
|
{:error, {:internal_server_error, "internal server error"}, conn}
|
||||||
|> Text.encode_response()
|
|> Text.encode_response()
|
||||||
|
|
|
@ -3,7 +3,10 @@ defmodule Shortnr.URL.Repo.DETS do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def get(key) do
|
def get(key) do
|
||||||
{:ok, :dets.lookup(:urls, key) |> List.first() |> elem(1)}
|
case :dets.lookup(:urls, key) |> List.first() do
|
||||||
|
{_, url} -> {:ok, url}
|
||||||
|
nil -> {:ok, nil}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -8,7 +8,12 @@ defmodule Shortnr.URL do
|
||||||
updated_at: DateTime.utc_now(),
|
updated_at: DateTime.utc_now(),
|
||||||
url: %URI{}
|
url: %URI{}
|
||||||
|
|
||||||
@type t :: %__MODULE__{id: String.t(), url: URI.t()}
|
@type t :: %__MODULE__{
|
||||||
|
id: String.t(),
|
||||||
|
url: URI.t(),
|
||||||
|
created_at: DateTime.t(),
|
||||||
|
updated_at: DateTime.t()
|
||||||
|
}
|
||||||
|
|
||||||
@spec create(String.t(), module()) :: {:ok, String.t()} | Transport.error()
|
@spec create(String.t(), module()) :: {:ok, String.t()} | Transport.error()
|
||||||
def create(url, repo) do
|
def create(url, repo) do
|
||||||
|
|
Loading…
Reference in New Issue