Format with mix format

This commit is contained in:
Ben Busby 2021-10-23 15:18:13 -06:00
parent 76faebd234
commit 2ea805bd88
No known key found for this signature in database
GPG key ID: 339B7B7EB5333D14
2 changed files with 24 additions and 19 deletions

View file

@ -1,4 +1,4 @@
import Config
import Config
config :privacy_revolver,
redis_conn: "redis://localhost:6379",

View file

@ -3,8 +3,8 @@ defmodule PrivacyRevolver.Router do
use Plug.Router
plug :match
plug :dispatch
plug(:match)
plug(:dispatch)
get "/" do
send_resp(conn, 200, "")
@ -18,27 +18,32 @@ defmodule PrivacyRevolver.Router do
get "/:service/*glob" do
path = Enum.join(glob, "/")
{:ok, instances} = Redix.command(
:redix,
["LRANGE", service, "0", "-1"]
)
{:ok, instances} =
Redix.command(
:redix,
["LRANGE", service, "0", "-1"]
)
# Either pick a random available instance,
# or fall back to the default one
instance = if Enum.count(instances) > 0 do
Enum.random(instances)
else
{:ok, result} = Redix.command(
:redix,
["GET", "#{service}#{@fallback_str}"]
)
result
end
instance =
if Enum.count(instances) > 0 do
Enum.random(instances)
else
{:ok, result} =
Redix.command(
:redix,
["GET", "#{service}#{@fallback_str}"]
)
result
end
# Redirect to the available instance
conn |>
Plug.Conn.resp(:found, "") |>
Plug.Conn.put_resp_header(
conn
|> Plug.Conn.resp(:found, "")
|> Plug.Conn.put_resp_header(
"location",
"#{instance}/#{path}"
)