cerrado @ 2dd4cf35aab8324608a83d337459fd8354521b92

 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}