From 96c0784f99e134156be8b751607aad1e78bbc094 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 5 Apr 2025 17:41:25 +0800 Subject: HTTP: Replace if-else chain with switch --- http_handle_repo_raw.go | 7 ++++--- http_handle_repo_tree.go | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/http_handle_repo_raw.go b/http_handle_repo_raw.go index 54ca931..ea2925c 100644 --- a/http_handle_repo_raw.go +++ b/http_handle_repo_raw.go @@ -36,18 +36,19 @@ func httpHandleRepoRaw(writer http.ResponseWriter, request *http.Request, params return } - if files != nil { + switch { + case files != nil: params["files"] = files params["readme_filename"] = "README.md" params["readme"] = template.HTML("

README rendering here is WIP again

") // TODO renderTemplate(writer, "repo_raw_dir", params) - } else if content != "" { + case content != "": if redirectNoDir(writer, request) { return } writer.Header().Set("Content-Type", "application/octet-stream") fmt.Fprint(writer, content) - } else { + default: errorPage500(writer, params, "Unknown error fetching repo raw data") } } diff --git a/http_handle_repo_tree.go b/http_handle_repo_tree.go index d577f48..889406b 100644 --- a/http_handle_repo_tree.go +++ b/http_handle_repo_tree.go @@ -37,16 +37,17 @@ func httpHandleRepoTree(writer http.ResponseWriter, request *http.Request, param return } - if files != nil { + switch { + case files != nil: params["files"] = files params["readme_filename"] = "README.md" params["readme"] = template.HTML("

README rendering here is WIP again

") // TODO renderTemplate(writer, "repo_tree_dir", params) - } else if content != "" { + case content != "": rendered := renderHighlightedFile(pathSpec, content) params["file_contents"] = rendered renderTemplate(writer, "repo_tree_file", params) - } else { + default: errorPage500(writer, params, "Unknown object type, something is seriously wrong") } } -- cgit v1.2.3