cerrado @ 242ba7f412d4e54f21385afff3f2b884f57f6ced

 1package git
 2
 3import (
 4	"log/slog"
 5	"net/http"
 6
 7	"git.gabrielgio.me/cerrado/pkg/service"
 8	"git.gabrielgio.me/cerrado/templates"
 9)
10
11type (
12	GitHandler struct {
13		gitService gitService
14	}
15
16	gitService interface {
17		ListRepositories() ([]*service.Repository, error)
18	}
19)
20
21func NewGitHandler(gitService gitService) *GitHandler {
22	return &GitHandler{
23		gitService: gitService,
24	}
25}
26
27func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) {
28	repos, err := g.gitService.ListRepositories()
29	if err != nil {
30		slog.Error("Error listing repo", "error", err)
31		return
32	}
33
34	gitList := &templates.GitListPage{repos}
35	templates.WritePageTemplate(w, gitList)
36}