1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-19 10:57:05 +00:00
Former-commit-id: 8f99121b81dc76c04d5910117885d9286873f26c
This commit is contained in:
kataras
2017-12-04 05:08:05 +02:00
parent 7043f352d9
commit a7b2a90e3b
16 changed files with 1719 additions and 0 deletions

50
mvc2/binder/to_struct.go Normal file
View File

@@ -0,0 +1,50 @@
package binder
import (
"reflect"
)
type StructBinding struct {
Field StructValue
Func FuncResultValue
}
func (b *StructBinding) AddSource(dest reflect.Value, source ...reflect.Value) {
typ := indirectTyp(dest.Type()) //indirectTyp(reflect.TypeOf(dest))
if typ.Kind() != reflect.Struct {
return
}
fields := lookupFields(typ, -1)
for _, f := range fields {
for _, s := range source {
if s.Type().Kind() == reflect.Func {
returnValue, outType, err := makeReturnValue(s)
if err != nil {
continue
}
gotTyp = outType
service.ReturnValue = returnValue
}
gotTyp := s.Type()
v := StructValue{
Type: gotTyp,
Value: s,
FieldIndex: f.Index,
}
if equalTypes(gotTyp, f.Type) {
service.Type = gotTyp
_serv = append(_serv, &service)
fmt.Printf("[2] Bind In=%s->%s for struct field[%d]\n", f.Type, gotTyp.String(), f.Index)
break
}
}
}
fmt.Printf("[2] Bind %d for %s\n", len(_serv), typ.String())
*serv = _serv
return
}