Add check invoked method
This commit is contained in:
parent
4218467ab3
commit
b0e66a4aa6
1 changed files with 10 additions and 3 deletions
13
traefik.go
13
traefik.go
|
@ -290,7 +290,10 @@ func LoadConfig(configurations configs, globalConfiguration *GlobalConfiguration
|
||||||
newRoute := router.NewRoute().Name(frontendName)
|
newRoute := router.NewRoute().Name(frontendName)
|
||||||
for routeName, route := range frontend.Routes {
|
for routeName, route := range frontend.Routes {
|
||||||
log.Debugf("Creating route %s %s:%s", routeName, route.Rule, route.Value)
|
log.Debugf("Creating route %s %s:%s", routeName, route.Rule, route.Value)
|
||||||
newRouteReflect := Invoke(newRoute, route.Rule, route.Value)
|
newRouteReflect, err := invoke(newRoute, route.Rule, route.Value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
newRoute = newRouteReflect[0].Interface().(*mux.Route)
|
newRoute = newRouteReflect[0].Interface().(*mux.Route)
|
||||||
}
|
}
|
||||||
if backends[frontend.Backend] == nil {
|
if backends[frontend.Backend] == nil {
|
||||||
|
@ -354,10 +357,14 @@ func LoadConfig(configurations configs, globalConfiguration *GlobalConfiguration
|
||||||
|
|
||||||
// Invoke calls the specified method with the specified arguments on the specified interface.
|
// Invoke calls the specified method with the specified arguments on the specified interface.
|
||||||
// It uses the go(lang) reflect package.
|
// It uses the go(lang) reflect package.
|
||||||
func Invoke(any interface{}, name string, args ...interface{}) []reflect.Value {
|
func invoke(any interface{}, name string, args ...interface{}) ([]reflect.Value, error) {
|
||||||
inputs := make([]reflect.Value, len(args))
|
inputs := make([]reflect.Value, len(args))
|
||||||
for i := range args {
|
for i := range args {
|
||||||
inputs[i] = reflect.ValueOf(args[i])
|
inputs[i] = reflect.ValueOf(args[i])
|
||||||
}
|
}
|
||||||
return reflect.ValueOf(any).MethodByName(name).Call(inputs)
|
method := reflect.ValueOf(any).MethodByName(name)
|
||||||
|
if method.IsValid() {
|
||||||
|
return method.Call(inputs), nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("Method not found: " + name)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue