mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
3945fa68d1
We have to do the same on iris-contrib/examples, iris-contrib/middleware and e.t.c. Former-commit-id: 0860688158f374bc137bc934b81b26dcd0e10964
48 lines
941 B
Go
48 lines
941 B
Go
package mvc
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/kataras/iris/v12/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)
|
|
for i := 0; i < n; i++ {
|
|
funcIn[i] = funcTyp.In(i)
|
|
}
|
|
return funcIn
|
|
}
|