aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/incoming/web/handlers
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-08-18 02:09:50 +0800
committerRunxi Yu <me@runxiyu.org>2025-08-18 02:09:50 +0800
commitaa63d26cdd4284faf67f9582d34a12c8767aed15 (patch)
treebd895fd2c5a87b4cf5d943775e6a1eff730886bd /forged/internal/incoming/web/handlers
parentAdd templates and static paths to the web config (diff)
downloadforge-aa63d26cdd4284faf67f9582d34a12c8767aed15.tar.gz
forge-aa63d26cdd4284faf67f9582d34a12c8767aed15.tar.zst
forge-aa63d26cdd4284faf67f9582d34a12c8767aed15.zip
Add template rendering
Diffstat (limited to 'forged/internal/incoming/web/handlers')
-rw-r--r--forged/internal/incoming/web/handlers/group.go14
-rw-r--r--forged/internal/incoming/web/handlers/index.go17
-rw-r--r--forged/internal/incoming/web/handlers/repo/index.go18
3 files changed, 38 insertions, 11 deletions
diff --git a/forged/internal/incoming/web/handlers/group.go b/forged/internal/incoming/web/handlers/group.go
index 1a1cb1d..0c631c3 100644
--- a/forged/internal/incoming/web/handlers/group.go
+++ b/forged/internal/incoming/web/handlers/group.go
@@ -4,14 +4,22 @@ import (
"net/http"
"strings"
+ "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/templates"
wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
)
-type GroupHTTP struct{}
+type GroupHTTP struct {
+ r templates.Renderer
+}
-func NewGroupHTTP() *GroupHTTP { return &GroupHTTP{} }
+func NewGroupHTTP(r templates.Renderer) *GroupHTTP { return &GroupHTTP{r: r} }
func (h *GroupHTTP) Index(w http.ResponseWriter, r *http.Request, _ wtypes.Vars) {
base := wtypes.Base(r)
- _, _ = w.Write([]byte("group index for: /" + strings.Join(base.GroupPath, "/") + "/"))
+ _ = h.r.Render(w, "group/index.html", struct {
+ GroupPath string
+ }{
+ GroupPath: "/" + strings.Join(base.GroupPath, "/") + "/",
+ })
}
+
diff --git a/forged/internal/incoming/web/handlers/index.go b/forged/internal/incoming/web/handlers/index.go
index 1fd2954..259ca4a 100644
--- a/forged/internal/incoming/web/handlers/index.go
+++ b/forged/internal/incoming/web/handlers/index.go
@@ -1,15 +1,26 @@
package handlers
import (
+ "log"
"net/http"
+ "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/templates"
wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
)
-type IndexHTTP struct{}
+type IndexHTTP struct {
+ r templates.Renderer
+}
-func NewIndexHTTP() *IndexHTTP { return &IndexHTTP{} }
+func NewIndexHTTP(r templates.Renderer) *IndexHTTP { return &IndexHTTP{r: r} }
func (h *IndexHTTP) Index(w http.ResponseWriter, _ *http.Request, _ wtypes.Vars) {
- _, _ = w.Write([]byte("index: replace with template render"))
+ err := h.r.Render(w, "index", struct {
+ Title string
+ }{
+ Title: "Home",
+ })
+ if err != nil {
+ log.Println("failed to render index page", "error", err)
+ }
}
diff --git a/forged/internal/incoming/web/handlers/repo/index.go b/forged/internal/incoming/web/handlers/repo/index.go
index 3a6d7ea..dd1382f 100644
--- a/forged/internal/incoming/web/handlers/repo/index.go
+++ b/forged/internal/incoming/web/handlers/repo/index.go
@@ -1,20 +1,28 @@
package repo
import (
- "fmt"
"net/http"
"strings"
+ "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/templates"
wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
)
-type HTTP struct{}
+type HTTP struct {
+ r templates.Renderer
+}
-func NewHTTP() *HTTP { return &HTTP{} }
+func NewHTTP(r templates.Renderer) *HTTP { return &HTTP{r: r} }
func (h *HTTP) Index(w http.ResponseWriter, r *http.Request, v wtypes.Vars) {
base := wtypes.Base(r)
repo := v["repo"]
- _, _ = w.Write([]byte(fmt.Sprintf("repo index: group=%q repo=%q",
- "/"+strings.Join(base.GroupPath, "/")+"/", repo)))
+ _ = h.r.Render(w, "repo/index.html", struct {
+ Group string
+ Repo string
+ }{
+ Group: "/" + strings.Join(base.GroupPath, "/") + "/",
+ Repo: repo,
+ })
}
+