Routing Support #4

Merged
cerbervs merged 5 commits from feat/routing into main 2025-09-06 21:58:04 +00:00
Showing only changes of commit 4316ab2197 - Show all commits

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