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

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

View File

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