aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/git/handler.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/handler/git/handler.go')
-rw-r--r--pkg/handler/git/handler.go61
1 files changed, 27 insertions, 34 deletions
diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go
index 7bdf372..d952fef 100644
--- a/pkg/handler/git/handler.go
+++ b/pkg/handler/git/handler.go
@@ -3,7 +3,6 @@ package git
import (
"bytes"
"io"
- "log/slog"
"net/http"
"os"
"path/filepath"
@@ -50,23 +49,20 @@ func NewGitHandler(gitService gitService, confRepo configurationRepository) *Git
}
}
-func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) {
+func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) error {
repos, err := g.gitService.ListRepositories()
if err != nil {
- slog.Error("Error listing repo", "error", err)
- return
+ return err
}
f, err := os.Open(g.readmePath)
if err != nil {
- slog.Error("Error loading readme file", "error", err)
- return
+ return err
}
bs, err := io.ReadAll(f)
if err != nil {
- slog.Error("Error reading readme file bytes", "error", err)
- return
+ return err
}
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
@@ -84,15 +80,15 @@ func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) {
About: bs,
}
templates.WritePageTemplate(w, gitList)
+ return nil
}
-func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) {
+func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) error {
ext.SetHTML(w)
name := r.PathValue("name")
ref, err := g.gitService.GetHead(name)
if err != nil {
- slog.Error("Error loading head", "error", err)
- return
+ return err
}
gitList := &templates.GitItemPage{
@@ -101,15 +97,15 @@ func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) {
GitItemBase: &templates.GitItemSummaryPage{},
}
templates.WritePageTemplate(w, gitList)
+ return nil
}
-func (g *GitHandler) About(w http.ResponseWriter, r *http.Request) {
+func (g *GitHandler) About(w http.ResponseWriter, r *http.Request) error {
ext.SetHTML(w)
name := r.PathValue("name")
ref, err := g.gitService.GetHead(name)
if err != nil {
- slog.Error("Error loading head", "error", err)
- return
+ return err
}
gitList := &templates.GitItemPage{
Name: name,
@@ -117,28 +113,26 @@ func (g *GitHandler) About(w http.ResponseWriter, r *http.Request) {
GitItemBase: &templates.GitItemAboutPage{},
}
templates.WritePageTemplate(w, gitList)
+ return nil
}
-func (g *GitHandler) Refs(w http.ResponseWriter, r *http.Request) {
+func (g *GitHandler) Refs(w http.ResponseWriter, r *http.Request) error {
ext.SetHTML(w)
name := r.PathValue("name")
tags, err := g.gitService.ListTags(name)
if err != nil {
- slog.Error("Error loading tags", "error", err)
- return
+ return err
}
branches, err := g.gitService.ListBranches(name)
if err != nil {
- slog.Error("Error loading branches", "error", err)
- return
+ return err
}
ref, err := g.gitService.GetHead(name)
if err != nil {
- slog.Error("Error loading head", "error", err)
- return
+ return err
}
gitList := &templates.GitItemPage{
@@ -150,9 +144,10 @@ func (g *GitHandler) Refs(w http.ResponseWriter, r *http.Request) {
},
}
templates.WritePageTemplate(w, gitList)
+ return nil
}
-func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) {
+func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) error {
ext.SetHTML(w)
name := r.PathValue("name")
ref := r.PathValue("ref")
@@ -160,8 +155,7 @@ func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) {
tree, err := g.gitService.GetTree(name, ref, rest)
if err != nil {
- slog.Error("Error loading tree", "error", err)
- return
+ return err
}
gitList := &templates.GitItemPage{
@@ -175,9 +169,10 @@ func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) {
},
}
templates.WritePageTemplate(w, gitList)
+ return nil
}
-func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) {
+func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) error {
ext.SetHTML(w)
name := r.PathValue("name")
ref := r.PathValue("ref")
@@ -185,8 +180,7 @@ func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) {
file, err := g.gitService.GetFileContent(name, ref, rest)
if err != nil {
- slog.Error("Error loading blob", "error", err)
- return
+ return err
}
filename := filepath.Base(rest)
@@ -197,15 +191,13 @@ func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) {
)
iterator, err := lexer.Tokenise(nil, file)
if err != nil {
- slog.Error("Error tokenise", "error", err)
- return
+ return err
}
var code bytes.Buffer
err = formatter.Format(&code, style, iterator)
if err != nil {
- slog.Error("Error format", "error", err)
- return
+ return err
}
gitList := &templates.GitItemPage{
@@ -217,17 +209,17 @@ func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) {
},
}
templates.WritePageTemplate(w, gitList)
+ return nil
}
-func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) {
+func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) error {
ext.SetHTML(w)
name := r.PathValue("name")
ref := r.PathValue("ref")
commits, err := g.gitService.ListCommits(name, ref)
if err != nil {
- slog.Error("Error loading commits", "error", err)
- return
+ return err
}
gitList := &templates.GitItemPage{
@@ -238,6 +230,7 @@ func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) {
},
}
templates.WritePageTemplate(w, gitList)
+ return nil
}
func GetLexers(filename string) chroma.Lexer {