aboutsummaryrefslogtreecommitdiff
path: root/http_handle_repo_tree.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-22 13:44:03 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-22 13:44:03 +0800
commit99fd8a9cf96a51fcd9e50445cb035cc9ecd012de (patch)
tree077812874d2650216549048524886059391b5d45 /http_handle_repo_tree.go
parentInitial linting (diff)
downloadforge-99fd8a9cf96a51fcd9e50445cb035cc9ecd012de.tar.gz
forge-99fd8a9cf96a51fcd9e50445cb035cc9ecd012de.tar.zst
forge-99fd8a9cf96a51fcd9e50445cb035cc9ecd012de.zip
Variable name lengths
Diffstat (limited to 'http_handle_repo_tree.go')
-rw-r--r--http_handle_repo_tree.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/http_handle_repo_tree.go b/http_handle_repo_tree.go
index 36eefc0..1238fd5 100644
--- a/http_handle_repo_tree.go
+++ b/http_handle_repo_tree.go
@@ -19,7 +19,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/object"
)
-func httpHandleRepoTree(w http.ResponseWriter, r *http.Request, params map[string]any) {
+func httpHandleRepoTree(writer http.ResponseWriter, request *http.Request, params map[string]any) {
var rawPathSpec, pathSpec string
var repo *git.Repository
var refHash plumbing.Hash
@@ -32,15 +32,15 @@ func httpHandleRepoTree(w http.ResponseWriter, r *http.Request, params map[strin
params["path_spec"] = pathSpec
if refHash, err = getRefHash(repo, params["ref_type"].(string), params["ref_name"].(string)); err != nil {
- http.Error(w, "Error getting ref hash: "+err.Error(), http.StatusInternalServerError)
+ http.Error(writer, "Error getting ref hash: "+err.Error(), http.StatusInternalServerError)
return
}
if commitObject, err = repo.CommitObject(refHash); err != nil {
- http.Error(w, "Error getting commit object: "+err.Error(), http.StatusInternalServerError)
+ http.Error(writer, "Error getting commit object: "+err.Error(), http.StatusInternalServerError)
return
}
if tree, err = commitObject.Tree(); err != nil {
- http.Error(w, "Error getting file tree: "+err.Error(), http.StatusInternalServerError)
+ http.Error(writer, "Error getting file tree: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -58,14 +58,14 @@ func httpHandleRepoTree(w http.ResponseWriter, r *http.Request, params map[strin
var formattedHTML template.HTML
if file, err = tree.File(pathSpec); err != nil {
- http.Error(w, "Error retrieving path: "+err.Error(), http.StatusInternalServerError)
+ http.Error(writer, "Error retrieving path: "+err.Error(), http.StatusInternalServerError)
return
}
- if redirectNoDir(w, r) {
+ if redirectNoDir(writer, request) {
return
}
if fileContent, err = file.Contents(); err != nil {
- http.Error(w, "Error reading file: "+err.Error(), http.StatusInternalServerError)
+ http.Error(writer, "Error reading file: "+err.Error(), http.StatusInternalServerError)
return
}
lexer = chromaLexers.Match(pathSpec)
@@ -73,31 +73,31 @@ func httpHandleRepoTree(w http.ResponseWriter, r *http.Request, params map[strin
lexer = chromaLexers.Fallback
}
if iterator, err = lexer.Tokenise(nil, fileContent); err != nil {
- http.Error(w, "Error tokenizing code: "+err.Error(), http.StatusInternalServerError)
+ http.Error(writer, "Error tokenizing code: "+err.Error(), http.StatusInternalServerError)
return
}
var formattedHTMLStr bytes.Buffer
style = chromaStyles.Get("autumn")
formatter = chromaHTML.New(chromaHTML.WithClasses(true), chromaHTML.TabWidth(8))
if err = formatter.Format(&formattedHTMLStr, style, iterator); err != nil {
- http.Error(w, "Error formatting code: "+err.Error(), http.StatusInternalServerError)
+ http.Error(writer, "Error formatting code: "+err.Error(), http.StatusInternalServerError)
return
}
formattedHTML = template.HTML(formattedHTMLStr.Bytes()) //#nosec G203
params["file_contents"] = formattedHTML
- renderTemplate(w, "repo_tree_file", params)
+ renderTemplate(writer, "repo_tree_file", params)
return
}
}
if len(rawPathSpec) != 0 && rawPathSpec[len(rawPathSpec)-1] != '/' {
- http.Redirect(w, r, path.Base(pathSpec)+"/", http.StatusSeeOther)
+ http.Redirect(writer, request, path.Base(pathSpec)+"/", http.StatusSeeOther)
return
}
params["readme_filename"], params["readme"] = renderReadmeAtTree(target)
params["files"] = makeDisplayTree(target)
- renderTemplate(w, "repo_tree_dir", params)
+ renderTemplate(writer, "repo_tree_dir", params)
}