-
Notifications
You must be signed in to change notification settings - Fork 12
/
multi_route_component.go
44 lines (37 loc) · 1.44 KB
/
multi_route_component.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package fiber
// MultiRouteComponent - is a network component with zero or more possible routes,
// such as FanOut, Combiner, Router
type MultiRouteComponent interface {
Component
SetRoutes(routes map[string]Component)
GetRoutes() map[string]Component
}
// NewMultiRouteComponent is a factory function for creating a MultiRouteComponent
func NewMultiRouteComponent(id string) *BaseMultiRouteComponent {
return &BaseMultiRouteComponent{
BaseComponent: BaseComponent{id: id, kind: MultiRouteComponentKind},
}
}
// BaseMultiRouteComponent is a reference implementation of a MultiRouteComponent
type BaseMultiRouteComponent struct {
BaseComponent
routes map[string]Component
}
// SetRoutes sets possible routes for this multi-route component
func (multiRoute *BaseMultiRouteComponent) SetRoutes(routes map[string]Component) {
multiRoute.routes = routes
}
// GetRoutes is a getter for the routes configured on the BaseMultiRouteComponent
func (multiRoute *BaseMultiRouteComponent) GetRoutes() map[string]Component {
return multiRoute.routes
}
// AddInterceptor can be used to (optionally, recursively) add one or more interceptors to
// the BaseMultiRouteComponent
func (multiRoute *BaseMultiRouteComponent) AddInterceptor(recursive bool, interceptors ...Interceptor) {
if recursive {
for _, route := range multiRoute.routes {
route.AddInterceptor(recursive, interceptors...)
}
}
multiRoute.BaseComponent.AddInterceptor(recursive, interceptors...)
}