From 9f9f43751f53793a51db353c605643b8e704356f Mon Sep 17 00:00:00 2001 From: maddalax Date: Thu, 10 Oct 2024 21:01:39 -0500 Subject: [PATCH] handle /item redirect --- examples/hackernews/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/hackernews/main.go b/examples/hackernews/main.go index 575e42c..1d38712 100644 --- a/examples/hackernews/main.go +++ b/examples/hackernews/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/maddalax/htmgo/framework/h" "github.com/maddalax/htmgo/framework/service" "hackernews/__htmgo" @@ -23,6 +24,11 @@ func main() { http.FileServerFS(sub) + app.Router.Handle("/item", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + id := r.URL.Query().Get("id") + w.Header().Set("Location", fmt.Sprintf("/?item=%s", id)) + w.WriteHeader(302) + })) app.Router.Handle("/public/*", http.StripPrefix("/public", http.FileServerFS(sub))) __htmgo.Register(app.Router) },