2017-12-16 05:38:28 +01:00
|
|
|
package mvc
|
2017-12-04 04:08:05 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/context"
|
|
|
|
"github.com/kataras/iris/v12/macro"
|
2017-12-04 04:08:05 +01:00
|
|
|
)
|
|
|
|
|
2019-09-07 04:57:35 +02:00
|
|
|
func getPathParamsForInput(startParamIndex int, params []macro.TemplateParam, funcIn ...reflect.Type) (values []reflect.Value) {
|
2017-12-04 04:08:05 +01:00
|
|
|
if len(funcIn) == 0 || len(params) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-21 18:20:05 +02:00
|
|
|
// consumedParams := make(map[int]bool, 0)
|
|
|
|
// for _, in := range funcIn {
|
|
|
|
// for j, p := range params {
|
|
|
|
// if _, consumed := consumedParams[j]; consumed {
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // fmt.Printf("%s input arg type vs %s param type\n", in.Kind().String(), p.Type.Kind().String())
|
|
|
|
// if m := macros.Lookup(p.Type); m != nil && m.GoType == in.Kind() {
|
|
|
|
// consumedParams[j] = true
|
|
|
|
// // fmt.Printf("param.go: bind path param func for paramName = '%s' and paramType = '%s'\n", paramName, paramType.String())
|
|
|
|
// funcDep, ok := context.ParamResolverByKindAndIndex(m.GoType, p.Index)
|
|
|
|
// // funcDep, ok := context.ParamResolverByKindAndKey(in.Kind(), paramName)
|
|
|
|
// if !ok {
|
|
|
|
// // here we can add a logger about invalid parameter type although it should never happen here
|
|
|
|
// // unless the end-developer modified the macro/macros with a special type but not the context/ParamResolvers.
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// values = append(values, funcDep)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2019-03-01 13:10:07 +01:00
|
|
|
consumed := make(map[int]struct{})
|
|
|
|
for _, in := range funcIn {
|
|
|
|
for j, param := range params {
|
|
|
|
if _, ok := consumed[j]; ok {
|
|
|
|
continue
|
|
|
|
}
|
2019-07-11 15:33:20 +02:00
|
|
|
|
2019-09-07 04:57:35 +02:00
|
|
|
funcDep, ok := context.ParamResolverByTypeAndIndex(in, startParamIndex+param.Index)
|
2019-03-01 13:10:07 +01:00
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
values = append(values, funcDep)
|
|
|
|
consumed[j] = struct{}{}
|
|
|
|
break
|
2017-12-10 06:00:51 +01:00
|
|
|
}
|
2017-12-04 04:08:05 +01:00
|
|
|
}
|
|
|
|
|
2018-10-21 18:20:05 +02:00
|
|
|
return
|
2017-12-04 04:08:05 +01:00
|
|
|
}
|