mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
implement mvc HandleError as requested at #1244
Former-commit-id: 58a69f9cffe67c3aa1bab5d9425c5df65e2367ed
This commit is contained in:
@@ -1,13 +1,42 @@
|
||||
package mvc
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
var baseControllerTyp = reflect.TypeOf((*BaseController)(nil)).Elem()
|
||||
"github.com/kataras/iris/hero"
|
||||
)
|
||||
|
||||
var (
|
||||
baseControllerTyp = reflect.TypeOf((*BaseController)(nil)).Elem()
|
||||
errorHandlerTyp = reflect.TypeOf((*hero.ErrorHandler)(nil)).Elem()
|
||||
errorTyp = reflect.TypeOf((*error)(nil)).Elem()
|
||||
)
|
||||
|
||||
func isBaseController(ctrlTyp reflect.Type) bool {
|
||||
return ctrlTyp.Implements(baseControllerTyp)
|
||||
}
|
||||
|
||||
func isErrorHandler(ctrlTyp reflect.Type) bool {
|
||||
return ctrlTyp.Implements(errorHandlerTyp)
|
||||
}
|
||||
|
||||
func hasErrorOutArgs(fn reflect.Method) bool {
|
||||
n := fn.Type.NumOut()
|
||||
if n == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
if out := fn.Type.Out(i); out.Kind() == reflect.Interface {
|
||||
if out.Implements(errorTyp) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func getInputArgsFromFunc(funcTyp reflect.Type) []reflect.Type {
|
||||
n := funcTyp.NumIn()
|
||||
funcIn := make([]reflect.Type, n, n)
|
||||
|
||||
Reference in New Issue
Block a user