feat(03-03): add typed path params and per-plugin rollback
Compile regex and enum constraints at route registration so malformed and unknown IDs share a 404, and named rollback errors isolate one plugin's history. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -59,13 +59,19 @@ func (p *Plugin) Boot(app *backpack.App) error {
|
||||
func (p *Plugin) Routes(r pact.Router) error {
|
||||
r.Get("/items/{id}", func(w http.ResponseWriter, req *http.Request) {
|
||||
id, ok := surf.IntParam(req, "id")
|
||||
if !ok {
|
||||
if !ok || id != 1 {
|
||||
http.NotFound(w, req)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `{"id":%d}`, id)
|
||||
})
|
||||
r.Where("id", `[0-9]+`)
|
||||
r.Get("/kinds/{kind}", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `{"kind":%q}`, req.PathValue("kind"))
|
||||
})
|
||||
r.WhereIn("kind", "widget", "gadget")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user