From 4316ab2197fb281b5e00b1d7e00ebcd171368187 Mon Sep 17 00:00:00 2001 From: Mark Bailey Date: Sun, 31 Aug 2025 19:37:27 -0400 Subject: [PATCH] feat: add RouteInfo and Router --- http/routing.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 http/routing.go diff --git a/http/routing.go b/http/routing.go new file mode 100644 index 0000000..fd8152c --- /dev/null +++ b/http/routing.go @@ -0,0 +1,36 @@ +package handler + +import ( + "context" + "net/http" + + "github.com/go-chi/chi/v5" +) + +type Router interface { + chi.Router +} + +type RouteInfo struct { + Name string + Path string + Description string + Title string +} + +type routeInfoKey struct{} + +func withRouteName(name, path, description, title string) func(http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + info := RouteInfo{ + Name: name, + Path: path, + Description: description, + Title: title, + } + ctx := context.WithValue(r.Context(), routeInfoKey{}, info) + next.ServeHTTP(w, r.WithContext(ctx)) + }) + } +}