defmodule RlRepo.Router do require Logger @moduledoc """ """ def status_404() do placeholders = %{"reason" => "Unknown"} {404, "text/html", RlRepo.Template.template("404-error", placeholders)} end def route_1(path, request_type) do {200, "text/html", "Hi"} end def route_3(path, request_type) do Logger.info("#{request_type}") {repo_name, pkg_name, action} = path if action == "info" do Logger.info("fetching json") end {200, "application/json", "{\"pkg_name\": \"#{pkg_name}\"}"} end def route_4(path, request_type) do Logger.info("#{request_type}") {repo_name, sub_repo_name, pkg_name, action} = path {200, "text/html", "<p>Hi</p>"} end def parse_1_segment_path(path) do [repo_name | _] = path {repo_name} end def parse_3_segment_path(path) do [repo_name | rest] = path [pkg_name | rest] = rest [action | _] = rest Logger.info("REPO #{repo_name} PKG #{pkg_name} ACTION #{action}") {repo_name, pkg_name, action} end def parse_4_segment_path(path) do [repo_name | rest] = path [sub_repo_name | rest] = rest [pkg_name | rest] = rest [action | _] = rest Logger.info("REPO #{repo_name} SUB_REPO #{sub_repo_name} PKG #{pkg_name} ACTION #{action}") {repo_name, sub_repo_name, pkg_name, action} end end