FMT: mix fmt

This commit is contained in:
Able 2025-02-20 03:59:08 -06:00
parent dcc753a106
commit 70822b178e
3 changed files with 21 additions and 37 deletions

View file

@ -8,10 +8,10 @@ defmodule RlRepo.ClientHandler do
Logger.info("Processing client request.")
client_socket
|> read_request
|> create_response()
|> create_response_header()
|> write_response(client_socket)
|> read_request
|> create_response()
|> create_response_header()
|> write_response(client_socket)
end
def read_request(client_socket) do
@ -24,47 +24,37 @@ defmodule RlRepo.ClientHandler do
def create_response(request) do
# TODO: Split off the info I need from the request body and I guess pass it around also
Logger.info("REQUEST BODY #{request}")
Logger.info("Building response body.")
# TODO: Handle routing here.
a = String.split(request, "\n\r")
# Logger.info a
[get_line | rest] = a
[get_line | rest] = String.split(request, "\n\r")
b = String.split(get_line, " ")
[request_type | rest] = b
[path | rest] = rest
Logger.info("#{request_type} #{path}")
# Parse path
# Parse path ignoring leading and trailing slash
split_path = String.split(path, "/", trim: true)
# Ignore the first slash.
# [_ | rest ] = split_path
split_path_length = length(split_path)
ret =
case split_path_length do
1 ->
RlRepo.Router.parse_1_segment_path(rest)
|> RlRepo.Router.route_1(request_type)
case split_path_length do
1 ->
RlRepo.Router.parse_1_segment_path(rest)
|> RlRepo.Router.route_1(request_type)
3 ->
RlRepo.Router.parse_3_segment_path(rest)
|> RlRepo.Router.route_3(request_type)
3 ->
RlRepo.Router.parse_3_segment_path(rest)
|> RlRepo.Router.route_3(request_type)
4 ->
RlRepo.Router.parse_4_segment_path(rest)
|> RlRepo.Router.route_4(request_type)
4 ->
RlRepo.Router.parse_4_segment_path(rest)
|> RlRepo.Router.route_4(request_type)
# Note: Error handling.
_ ->
RlRepo.Router.status_404()
end
ret
# Note: Error handling.
_ ->
RlRepo.Router.status_404()
end
end
def create_return_code_string(return_code) do

View file

@ -10,12 +10,8 @@ defmodule RlRepo.Template do
def inner_template(body, replacements) do
# TODO: Check if there is any actual placeholders
v = String.contains?(body, "~(")
# Logger.info(v)
# v = String.contains?(body, "~(")
len = body |> String.split("~(") |> length()
# Logger.info(body)
template_step(replacements, body, len)
end

View file

@ -10,12 +10,10 @@ defmodule RlRepoTest do
assert RlRepo.Template.inner_template(body, placeholders) == "DONE"
end
test "multi template replace" do
body = "~(replace)abc~(replace)"
placeholders = %{"replace" => "DONE"}
assert RlRepo.Template.inner_template(body, placeholders) == "DONEabcDONE"
end
end