mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 10:57:05 +00:00
cm
Former-commit-id: 8f99121b81dc76c04d5910117885d9286873f26c
This commit is contained in:
50
mvc2/binder/to_struct.go
Normal file
50
mvc2/binder/to_struct.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user