[feat] 完善 Router.Call Router.Get 方法

This commit is contained in:
what 2024-11-26 17:00:24 +08:00
parent fd3625802b
commit bccb0382d8

View File

@ -80,8 +80,8 @@ type RouteMiddleware interface {
} }
type Router interface { type Router interface {
Call(r *http.Request, code string, params map[string]any, opts ..._RouteFilter) (HttpResponse, error) Call(r *http.Request, code string, params map[string]any, opts ...RouteFilterOption) (HttpResponse, error)
Get(uuid string, opts ..._RouteFilter) (Route, bool) Get(uuid string, opts ...RouteFilterOption) (Route, bool)
Register(cr chi.Router) Register(cr chi.Router)
RefreshRoutes() error RefreshRoutes() error
} }
@ -108,22 +108,22 @@ type RouteParam interface {
InjectRequestToGlobalParams(*http.Request, GlobalParams) error InjectRequestToGlobalParams(*http.Request, GlobalParams) error
} }
type _RouteFilter func(opts *RouteFilterOption) type RouteFilterOption func(opts *RouteFilterOptions)
type RouteFilterOption struct { type RouteFilterOptions struct {
categories []RouteCategory categories []RouteCategory
services []RouteService services []RouteService
} }
func (this RouteFilterOption) RouteCategories() []RouteCategory { func (this RouteFilterOptions) RouteCategories() []RouteCategory {
return this.categories return this.categories
} }
func (this RouteFilterOption) RouteServices() []RouteService { func (this RouteFilterOptions) RouteServices() []RouteService {
return this.services return this.services
} }
func RouteFilter[T RouteCategory | RouteService](v T) _RouteFilter { func RouteFilter[T RouteCategory | RouteService](v T) RouteFilterOption {
return func(opt *RouteFilterOption) { return func(opt *RouteFilterOptions) {
switch value := any(v).(type) { switch value := any(v).(type) {
case RouteCategory: case RouteCategory:
opt.categories = append(opt.categories, value) opt.categories = append(opt.categories, value)