fix linter complaints
Alan Pearce alan@alanpearce.eu
Sat, 29 Mar 2025 21:11:08 +0100
5 files changed, 19 insertions(+), 10 deletions(-)
M git/git.go → git/git.go
@@ -111,10 +111,13 @@ return nil, fmt.Errorf("commits from ref: %w", err) } commits := []*object.Commit{} - ci.ForEach(func(c *object.Commit) error { + err = ci.ForEach(func(c *object.Commit) error { commits = append(commits, c) return nil }) + if err != nil { + return nil, fmt.Errorf("iterating commits: %w", err) + } return commits, nil }
M routes/git.go → routes/git.go
@@ -58,8 +58,7 @@ Dir: repo, Stdout: w, } - var reader io.ReadCloser - reader = r.Body + var reader io.ReadCloser = r.Body if r.Header.Get("Content-Encoding") == "gzip" { reader, err := gzip.NewReader(r.Body)
M routes/handler.go → routes/handler.go
@@ -1,6 +1,7 @@ package routes import ( + "log" "net/http" "go.alanpearce.eu/elgit/config" @@ -13,7 +14,14 @@ path := r.PathValue("rest") if r.URL.RawQuery == "service=git-receive-pack" { w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("no pushing allowed!")) + _, err := w.Write([]byte("no pushing allowed!")) + if err != nil { + log.Println(err) + d.Write500(w) + + return + } + return }
M routes/routes.go → routes/routes.go
@@ -173,10 +173,7 @@ data["gomod"] = isGoModule(gr) if err := t.ExecuteTemplate(w, "repo", data); err != nil { log.Println(err) - return } - - return } func (d *deps) RepoTree(w http.ResponseWriter, r *http.Request) { @@ -217,7 +214,6 @@ data["desc"] = getDescription(path) data["dotdot"] = filepath.Dir(treePath) d.listFiles(files, data, w) - return } func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) {
M routes/template.go → routes/template.go
@@ -149,6 +149,9 @@ func (d *deps) showRaw(content string, w http.ResponseWriter) { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "text/plain") - w.Write([]byte(content)) - return + _, err := w.Write([]byte(content)) + if err != nil { + log.Println(err) + d.Write500(w) + } }