diff options
| author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-05-27 22:36:50 +0200 | 
|---|---|---|
| committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-05-27 22:42:16 +0200 | 
| commit | 2dd4cf35aab8324608a83d337459fd8354521b92 (patch) | |
| tree | b65ecc803260bc268332fb2fbce83ab5dd209dbc /pkg/handler/git | |
| parent | 60e8e751c76d949a28eefe0c5462e0cf17337217 (diff) | |
| download | cerrado-2dd4cf35aab8324608a83d337459fd8354521b92.tar.gz cerrado-2dd4cf35aab8324608a83d337459fd8354521b92.tar.bz2 cerrado-2dd4cf35aab8324608a83d337459fd8354521b92.zip | |
feat: Wraps handler into its own package
Although this creates more complex folder structure will allow in the
feature for a easier testing of those given handlers.
Diffstat (limited to 'pkg/handler/git')
| -rw-r--r-- | pkg/handler/git/handler.go | 36 | 
1 files changed, 36 insertions, 0 deletions
| diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go new file mode 100644 index 0000000..236ac41 --- /dev/null +++ b/pkg/handler/git/handler.go @@ -0,0 +1,36 @@ +package git + +import ( +	"log/slog" +	"net/http" + +	"git.gabrielgio.me/cerrado/pkg/service" +	"git.gabrielgio.me/cerrado/templates" +) + +type ( +	GitHandler struct { +		gitService gitService +	} + +	gitService interface { +		ListRepositories() ([]*service.Repository, error) +	} +) + +func NewGitHandler(gitService gitService) *GitHandler { +	return &GitHandler{ +		gitService: gitService, +	} +} + +func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) { +	repos, err := g.gitService.ListRepositories() +	if err != nil { +		slog.Error("Error listing repo", "error", err) +		return +	} + +	gitList := &templates.GitListPage{repos} +	templates.WritePageTemplate(w, gitList) +} | 
