feat: add RouteInfo and Router

This commit is contained in:
Mark Bailey 2025-08-31 19:37:27 -04:00
parent c770be157e
commit 4316ab2197

36
http/routing.go Normal file
View File

@ -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))
})
}
}