aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/incoming
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-08-17 18:14:35 +0800
committerRunxi Yu <me@runxiyu.org>2025-08-17 18:14:35 +0800
commit4479525731ef41bd5e2a91b949142a2097e0e701 (patch)
tree1c19df11472fdd2202df7158dafd0b15f59c3521 /forged/internal/incoming
parentMove all config typedefs to config.go (diff)
downloadforge-4479525731ef41bd5e2a91b949142a2097e0e701.tar.gz
forge-4479525731ef41bd5e2a91b949142a2097e0e701.tar.zst
forge-4479525731ef41bd5e2a91b949142a2097e0e701.zip
Move more stub handlers to handlers/
Diffstat (limited to 'forged/internal/incoming')
-rw-r--r--forged/internal/incoming/web/handler.go36
-rw-r--r--forged/internal/incoming/web/handlers/group.go17
-rw-r--r--forged/internal/incoming/web/handlers/index.go2
-rw-r--r--forged/internal/incoming/web/handlers/not_implemented.go15
-rw-r--r--forged/internal/incoming/web/handlers/repo/raw.go19
-rw-r--r--forged/internal/incoming/web/handlers/repo/tree.go19
-rw-r--r--forged/internal/incoming/web/stub.go38
7 files changed, 90 insertions, 56 deletions
diff --git a/forged/internal/incoming/web/handler.go b/forged/internal/incoming/web/handler.go
index 6341a93..10f85d6 100644
--- a/forged/internal/incoming/web/handler.go
+++ b/forged/internal/incoming/web/handler.go
@@ -25,33 +25,35 @@ func NewHandler(cfg Config) http.Handler {
// Feature handler instances
indexHTTP := handlers.NewIndexHTTP()
+ groupHTTP := handlers.NewGroupHTTP()
repoHTTP := repoHandlers.NewHTTP()
+ notImpl := handlers.NewNotImplementedHTTP()
// Index
h.r.GET("/", indexHTTP.Index)
// Top-level utilities
- h.r.ANY("-/login", h.notImplemented)
- h.r.ANY("-/users", h.notImplemented)
+ h.r.ANY("-/login", notImpl.Handle)
+ h.r.ANY("-/users", notImpl.Handle)
- // Group index (kept local for now; migrate later)
- h.r.GET("@group/", h.groupIndex)
+ // Group index
+ h.r.GET("@group/", groupHTTP.Index)
- // Repo index (handled by repoHTTP)
+ // Repo index
h.r.GET("@group/-/repos/:repo/", repoHTTP.Index)
- // Repo (kept local for now)
- h.r.ANY("@group/-/repos/:repo/info", h.notImplemented)
- h.r.ANY("@group/-/repos/:repo/git-upload-pack", h.notImplemented)
-
- // Repo features (kept local for now)
- h.r.GET("@group/-/repos/:repo/branches/", h.notImplemented)
- h.r.GET("@group/-/repos/:repo/log/", h.notImplemented)
- h.r.GET("@group/-/repos/:repo/commit/:commit", h.notImplemented)
- h.r.GET("@group/-/repos/:repo/tree/*rest", h.repoTree, WithDirIfEmpty("rest"))
- h.r.GET("@group/-/repos/:repo/raw/*rest", h.repoRaw, WithDirIfEmpty("rest"))
- h.r.GET("@group/-/repos/:repo/contrib/", h.notImplemented)
- h.r.GET("@group/-/repos/:repo/contrib/:mr", h.notImplemented)
+ // Repo (not implemented yet)
+ h.r.ANY("@group/-/repos/:repo/info", notImpl.Handle)
+ h.r.ANY("@group/-/repos/:repo/git-upload-pack", notImpl.Handle)
+
+ // Repo features
+ h.r.GET("@group/-/repos/:repo/branches/", notImpl.Handle)
+ h.r.GET("@group/-/repos/:repo/log/", notImpl.Handle)
+ h.r.GET("@group/-/repos/:repo/commit/:commit", notImpl.Handle)
+ h.r.GET("@group/-/repos/:repo/tree/*rest", repoHTTP.Tree, WithDirIfEmpty("rest"))
+ h.r.GET("@group/-/repos/:repo/raw/*rest", repoHTTP.Raw, WithDirIfEmpty("rest"))
+ h.r.GET("@group/-/repos/:repo/contrib/", notImpl.Handle)
+ h.r.GET("@group/-/repos/:repo/contrib/:mr", notImpl.Handle)
return h
}
diff --git a/forged/internal/incoming/web/handlers/group.go b/forged/internal/incoming/web/handlers/group.go
new file mode 100644
index 0000000..1a1cb1d
--- /dev/null
+++ b/forged/internal/incoming/web/handlers/group.go
@@ -0,0 +1,17 @@
+package handlers
+
+import (
+ "net/http"
+ "strings"
+
+ wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
+)
+
+type GroupHTTP struct{}
+
+func NewGroupHTTP() *GroupHTTP { return &GroupHTTP{} }
+
+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, "/") + "/"))
+}
diff --git a/forged/internal/incoming/web/handlers/index.go b/forged/internal/incoming/web/handlers/index.go
index 773a0c6..1fd2954 100644
--- a/forged/internal/incoming/web/handlers/index.go
+++ b/forged/internal/incoming/web/handlers/index.go
@@ -10,6 +10,6 @@ type IndexHTTP struct{}
func NewIndexHTTP() *IndexHTTP { return &IndexHTTP{} }
-func (h *IndexHTTP) Index(w http.ResponseWriter, r *http.Request, _ wtypes.Vars) {
+func (h *IndexHTTP) Index(w http.ResponseWriter, _ *http.Request, _ wtypes.Vars) {
_, _ = w.Write([]byte("index: replace with template render"))
}
diff --git a/forged/internal/incoming/web/handlers/not_implemented.go b/forged/internal/incoming/web/handlers/not_implemented.go
new file mode 100644
index 0000000..472f73b
--- /dev/null
+++ b/forged/internal/incoming/web/handlers/not_implemented.go
@@ -0,0 +1,15 @@
+package handlers
+
+import (
+ "net/http"
+
+ wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
+)
+
+type NotImplementedHTTP struct{}
+
+func NewNotImplementedHTTP() *NotImplementedHTTP { return &NotImplementedHTTP{} }
+
+func (h *NotImplementedHTTP) Handle(w http.ResponseWriter, _ *http.Request, _ wtypes.Vars) {
+ http.Error(w, "not implemented", http.StatusNotImplemented)
+}
diff --git a/forged/internal/incoming/web/handlers/repo/raw.go b/forged/internal/incoming/web/handlers/repo/raw.go
new file mode 100644
index 0000000..e421f45
--- /dev/null
+++ b/forged/internal/incoming/web/handlers/repo/raw.go
@@ -0,0 +1,19 @@
+package repo
+
+import (
+ "fmt"
+ "net/http"
+ "strings"
+
+ wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
+)
+
+func (h *HTTP) Raw(w http.ResponseWriter, r *http.Request, v wtypes.Vars) {
+ base := wtypes.Base(r)
+ repo := v["repo"]
+ rest := v["rest"]
+ if base.DirMode && rest != "" && !strings.HasSuffix(rest, "/") {
+ rest += "/"
+ }
+ _, _ = w.Write([]byte(fmt.Sprintf("raw: repo=%q path=%q", repo, rest)))
+}
diff --git a/forged/internal/incoming/web/handlers/repo/tree.go b/forged/internal/incoming/web/handlers/repo/tree.go
new file mode 100644
index 0000000..3432244
--- /dev/null
+++ b/forged/internal/incoming/web/handlers/repo/tree.go
@@ -0,0 +1,19 @@
+package repo
+
+import (
+ "fmt"
+ "net/http"
+ "strings"
+
+ wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
+)
+
+func (h *HTTP) Tree(w http.ResponseWriter, r *http.Request, v wtypes.Vars) {
+ base := wtypes.Base(r)
+ repo := v["repo"]
+ rest := v["rest"] // may be ""
+ if base.DirMode && rest != "" && !strings.HasSuffix(rest, "/") {
+ rest += "/"
+ }
+ _, _ = w.Write([]byte(fmt.Sprintf("tree: repo=%q path=%q", repo, rest)))
+}
diff --git a/forged/internal/incoming/web/stub.go b/forged/internal/incoming/web/stub.go
deleted file mode 100644
index 4fffd73..0000000
--- a/forged/internal/incoming/web/stub.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package web
-
-import (
- "fmt"
- "net/http"
- "strings"
-
- wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
-)
-
-func (h *handler) groupIndex(w http.ResponseWriter, r *http.Request, _ wtypes.Vars) {
- base := wtypes.Base(r)
- _, _ = w.Write([]byte("group index for: /" + strings.Join(base.GroupPath, "/") + "/"))
-}
-
-func (h *handler) repoTree(w http.ResponseWriter, r *http.Request, v wtypes.Vars) {
- base := wtypes.Base(r)
- repo := v["repo"]
- rest := v["rest"] // may be ""
- if base.DirMode && rest != "" && !strings.HasSuffix(rest, "/") {
- rest += "/"
- }
- _, _ = w.Write([]byte(fmt.Sprintf("tree: repo=%q path=%q", repo, rest)))
-}
-
-func (h *handler) repoRaw(w http.ResponseWriter, r *http.Request, v wtypes.Vars) {
- base := wtypes.Base(r)
- repo := v["repo"]
- rest := v["rest"]
- if base.DirMode && rest != "" && !strings.HasSuffix(rest, "/") {
- rest += "/"
- }
- _, _ = w.Write([]byte(fmt.Sprintf("raw: repo=%q path=%q", repo, rest)))
-}
-
-func (h *handler) notImplemented(w http.ResponseWriter, _ *http.Request, _ wtypes.Vars) {
- http.Error(w, "not implemented", http.StatusNotImplemented)
-}