Lindenii Project Forge
Move more stub handlers to handlers/
package web import ( "net/http" "path/filepath" handlers "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/handlers" repoHandlers "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/handlers/repo" ) type handler struct { r *Router } func NewHandler(cfg Config) http.Handler { h := &handler{r: NewRouter().ReverseProxy(cfg.ReverseProxy)} // Static files staticDir := filepath.Join(cfg.Root, "static") staticFS := http.FileServer(http.Dir(staticDir)) h.r.ANYHTTP("-/static/*rest", http.StripPrefix("/-/static/", staticFS), WithDirIfEmpty("rest"), ) // 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 (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 (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 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 } func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.r.ServeHTTP(w, r) }
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, "/") + "/")) }
package handlers import ( "net/http" wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types" ) 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")) }
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) }
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))) }
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))) }
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) }