[feat] 完善 Router.Call Router.Get 方法
This commit is contained in:
		
							parent
							
								
									4ef8c130a7
								
							
						
					
					
						commit
						fd3625802b
					
				
							
								
								
									
										29
									
								
								routing.go
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								routing.go
									
									
									
									
									
								
							| @ -80,8 +80,8 @@ type RouteMiddleware interface { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Router interface { | type Router interface { | ||||||
| 	Call(r *http.Request, code string, params map[string]any, category ...RouteCategory) (HttpResponse, error) | 	Call(r *http.Request, code string, params map[string]any, opts ..._RouteFilter) (HttpResponse, error) | ||||||
| 	Get(uuid string, category ...RouteCategory) (Route, bool) | 	Get(uuid string, opts ..._RouteFilter) (Route, bool) | ||||||
| 	Register(cr chi.Router) | 	Register(cr chi.Router) | ||||||
| 	RefreshRoutes() error | 	RefreshRoutes() error | ||||||
| } | } | ||||||
| @ -107,3 +107,28 @@ type RouteParam interface { | |||||||
| 	IsRequired() bool | 	IsRequired() bool | ||||||
| 	InjectRequestToGlobalParams(*http.Request, GlobalParams) error | 	InjectRequestToGlobalParams(*http.Request, GlobalParams) error | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | type _RouteFilter func(opts *RouteFilterOption) | ||||||
|  | type RouteFilterOption struct { | ||||||
|  | 	categories []RouteCategory | ||||||
|  | 	services   []RouteService | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (this RouteFilterOption) RouteCategories() []RouteCategory { | ||||||
|  | 	return this.categories | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (this RouteFilterOption) RouteServices() []RouteService { | ||||||
|  | 	return this.services | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func RouteFilter[T RouteCategory | RouteService](v T) _RouteFilter { | ||||||
|  | 	return func(opt *RouteFilterOption) { | ||||||
|  | 		switch value := any(v).(type) { | ||||||
|  | 		case RouteCategory: | ||||||
|  | 			opt.categories = append(opt.categories, value) | ||||||
|  | 		case RouteService: | ||||||
|  | 			opt.services = append(opt.services, value) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user