2017-12-16 05:38:28 +01:00
|
|
|
package mvc
|
|
|
|
|
2019-04-16 17:01:48 +02:00
|
|
|
import (
|
|
|
|
"reflect"
|
2017-12-16 05:38:28 +01:00
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/hero"
|
2019-04-16 17:01:48 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
baseControllerTyp = reflect.TypeOf((*BaseController)(nil)).Elem()
|
|
|
|
errorHandlerTyp = reflect.TypeOf((*hero.ErrorHandler)(nil)).Elem()
|
|
|
|
errorTyp = reflect.TypeOf((*error)(nil)).Elem()
|
|
|
|
)
|
2017-12-16 05:38:28 +01:00
|
|
|
|
|
|
|
func isBaseController(ctrlTyp reflect.Type) bool {
|
|
|
|
return ctrlTyp.Implements(baseControllerTyp)
|
|
|
|
}
|
|
|
|
|
2019-04-16 17:01:48 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-12-16 05:38:28 +01:00
|
|
|
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
|
|
|
|
}
|