feat: add RouteInfo and Router
This commit is contained in:
parent
c770be157e
commit
4316ab2197
36
http/routing.go
Normal file
36
http/routing.go
Normal 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))
|
||||
})
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user