37 lines
708 B
Go
37 lines
708 B
Go
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))
|
|
})
|
|
}
|
|
}
|