iris/mvc/reflect.go
Gerasimos (Makis) Maropoulos c13fd84354 fix https://github.com/kataras/iris/issues/1450 and continue on implementing 1449
Former-commit-id: 617f64d061e88f050a443ea1751fa244164656c5
2020-02-14 23:34:56 +02:00

48 lines
939 B
Go

package mvc
import (
"reflect"
"github.com/kataras/iris/v12/hero/di"
)
var (
baseControllerTyp = reflect.TypeOf((*BaseController)(nil)).Elem()
errorHandlerTyp = reflect.TypeOf((*di.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)
for i := 0; i < n; i++ {
funcIn[i] = funcTyp.In(i)
}
return funcIn
}