all repos — elgit @ 57b38c18e8257fd518b305669d350fdb9dee5703

fork of legit: web frontend for git, written in go

fix linter complaints
Alan Pearce alan@alanpearce.eu
Sat, 29 Mar 2025 21:11:08 +0100
commit

57b38c18e8257fd518b305669d350fdb9dee5703

parent

198873c58a72e4798289f4ff8a41d8a124625f00

5 files changed, 19 insertions(+), 10 deletions(-)

jump to
M git/git.gogit/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.goroutes/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.goroutes/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.goroutes/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.goroutes/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)
+	}
 }