feat(P1): Reach signup handler + templates + tests (REQ-040, G-026)
web/handlers/reach.go: GET /reach (list), GET /reach/new (form),
GET /reach/{id} (detail), POST /reach (atomic Reach+Stash create
per D-071, redirect 302). Labels "Create a Reach" (not the banned
legacy word). G-027 validation (non-empty, <=128, no path separators,
no template syntax). 3 Reach templates extend base.html.
reach_test.go: httptest for all 4 routes + atomic create + 400/409
error paths + rendered-HTML lexicon check on BOTH 200 and error bodies
(G-026). handlers/server.go: clone-per-page template pattern (avoids
content-block collision across pages). Coverage 81.2% on web/handlers.
---ci---
project: oy
phase: 1
milestone: v0.6
status: execute
---/ci---
This commit is contained in:
+13
-12
@@ -1,10 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/oy/openyield/web/handlers"
|
||||
"github.com/oy/openyield/web/store"
|
||||
)
|
||||
|
||||
func runServer() {
|
||||
@@ -13,29 +15,28 @@ func runServer() {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseGlob("web/templates/*.html")
|
||||
if err != nil {
|
||||
log.Fatalf("parse templates: %v", err)
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
srv, err := handlers.New(store.NewStore(), "web/templates")
|
||||
if err != nil {
|
||||
log.Fatalf("init handlers: %v", err)
|
||||
}
|
||||
srv.Register(mux)
|
||||
|
||||
// Home page (rendered via the handlers' page machinery too).
|
||||
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := tmpl.ExecuteTemplate(w, "home.html", nil); err != nil {
|
||||
log.Printf("render home: %v", err)
|
||||
}
|
||||
srv.RenderHome(w, nil)
|
||||
})
|
||||
|
||||
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
|
||||
|
||||
srv := &http.Server{Addr: ":" + port, Handler: mux}
|
||||
server := &http.Server{Addr: ":" + port, Handler: mux}
|
||||
log.Printf("OpenYield web on :%s", port)
|
||||
if err := srv.ListenAndServe(); err != nil {
|
||||
if err := server.ListenAndServe(); err != nil {
|
||||
log.Fatalf("server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user