aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/about.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-05-27 22:36:50 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-05-27 22:42:16 +0200
commit2dd4cf35aab8324608a83d337459fd8354521b92 (patch)
treeb65ecc803260bc268332fb2fbce83ab5dd209dbc /pkg/handler/about.go
parent60e8e751c76d949a28eefe0c5462e0cf17337217 (diff)
downloadcerrado-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/about.go')
-rw-r--r--pkg/handler/about.go51
1 files changed, 0 insertions, 51 deletions
diff --git a/pkg/handler/about.go b/pkg/handler/about.go
deleted file mode 100644
index 3ab2de8..0000000
--- a/pkg/handler/about.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package handler
-
-import (
- "io"
- "log/slog"
- "net/http"
- "os"
-
- "github.com/gomarkdown/markdown"
- "github.com/gomarkdown/markdown/html"
- "github.com/gomarkdown/markdown/parser"
-
- "git.gabrielgio.me/cerrado/templates"
-)
-
-type AboutHandler struct {
- readmePath string
-}
-
-func NewAboutHandler(readmePath string) *AboutHandler {
- return &AboutHandler{readmePath}
-}
-
-func (g *AboutHandler) About(w http.ResponseWriter, _ *http.Request) {
- f, err := os.Open(g.readmePath)
- if err != nil {
- slog.Error("Error loading readme file", "error", err)
- return
- }
-
- bs, err := io.ReadAll(f)
- if err != nil {
- slog.Error("Error reading readme file bytes", "error", err)
- return
- }
-
- extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
- p := parser.NewWithExtensions(extensions)
- doc := p.Parse(bs)
-
- htmlFlags := html.CommonFlags | html.HrefTargetBlank
- opts := html.RendererOptions{Flags: htmlFlags}
- renderer := html.NewRenderer(opts)
-
- bs = markdown.Render(doc, renderer)
-
- gitList := &templates.HelloPage{
- Body: bs,
- }
- templates.WritePageTemplate(w, gitList)
-}