diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-13 02:06:28 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-13 02:06:28 +0800 |
commit | b9d367b8fe76f2f96351bca85f092bd9d62308f8 (patch) | |
tree | d36a8ac3fb97296bb3329e0a561c523ab0666f72 /http_handle_repo_commit.go | |
parent | login: Stub login page (diff) | |
download | forge-b9d367b8fe76f2f96351bca85f092bd9d62308f8.tar.gz forge-b9d367b8fe76f2f96351bca85f092bd9d62308f8.tar.zst forge-b9d367b8fe76f2f96351bca85f092bd9d62308f8.zip |
http_handle_*.go: Use fmt.Fprintln, not w.Write
Diffstat (limited to '')
-rw-r--r-- | http_handle_repo_commit.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/http_handle_repo_commit.go b/http_handle_repo_commit.go index 073bfa1..1a84862 100644 --- a/http_handle_repo_commit.go +++ b/http_handle_repo_commit.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "net/http" "strings" @@ -20,23 +21,23 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[strin group_name, repo_name, commit_id_specified_string := params["group_name"].(string), params["repo_name"].(string), params["commit_id"].(string) repo, err := open_git_repo(r.Context(), group_name, repo_name) if err != nil { - _, _ = w.Write([]byte("Error opening repo: " + err.Error())) + fmt.Fprintln(w, "Error opening repo:", err.Error()) return } commit_id_specified_string_without_suffix := strings.TrimSuffix(commit_id_specified_string, ".patch") commit_id := plumbing.NewHash(commit_id_specified_string_without_suffix) commit_object, err := repo.CommitObject(commit_id) if err != nil { - _, _ = w.Write([]byte("Error getting commit object: " + err.Error())) + fmt.Fprintln(w, "Error getting commit object:", err.Error()) return } if commit_id_specified_string_without_suffix != commit_id_specified_string { patch, err := format_patch_from_commit(commit_object) if err != nil { - _, _ = w.Write([]byte("Error formatting patch: " + err.Error())) + fmt.Fprintln(w, "Error formatting patch:", err.Error()) return } - _, _ = w.Write([]byte(patch)) + fmt.Fprintln(w, patch) return } commit_id_string := commit_object.Hash.String() @@ -51,13 +52,13 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[strin parent_commit_hash, patch, err := get_patch_from_commit(commit_object) if err != nil { - _, _ = w.Write([]byte("Error getting patch from commit: " + err.Error())) + fmt.Fprintln(w, "Error getting patch from commit:", err.Error()) return } params["parent_commit_hash"] = parent_commit_hash.String() params["patch"] = patch - // TODO: Remove unnecessary context + // TODO: Remove unnecessary context // TODO: Prepend "+"/"-"/" " instead of solely distinguishing based on color usable_file_patches := make([]usable_file_patch, 0) for _, file_patch := range patch.FilePatches() { @@ -79,7 +80,7 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[strin err = templates.ExecuteTemplate(w, "repo_commit", params) if err != nil { - _, _ = w.Write([]byte("Error rendering template: " + err.Error())) + fmt.Fprintln(w, "Error rendering template:", err.Error()) return } } |