mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 21:15:56 +00:00
fix #1563 due to latest DI source changes
Former-commit-id: 3e3f209ebc60edf6a8702979f56e1f0ed73e4189
This commit is contained in:
@@ -101,22 +101,34 @@ func structFieldIgnored(f reflect.StructField) bool {
|
||||
return true // if not anonymous(embedded), ignore it.
|
||||
}
|
||||
|
||||
s := f.Tag.Get("ignore")
|
||||
return s == "true" // if has an ignore tag then ignore it.
|
||||
if s := f.Tag.Get("ignore"); s == "true" {
|
||||
return true
|
||||
}
|
||||
|
||||
if s := f.Tag.Get("stateless"); s == "true" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// all except non-zero.
|
||||
func lookupFields(elem reflect.Value, skipUnexported bool, onlyZeros bool, parentIndex []int) (fields []reflect.StructField) {
|
||||
func lookupFields(elem reflect.Value, skipUnexported bool, onlyZeros bool, parentIndex []int) (fields []reflect.StructField, stateless int) {
|
||||
elemTyp := elem.Type()
|
||||
for i, n := 0, elem.NumField(); i < n; i++ {
|
||||
field := elemTyp.Field(i)
|
||||
fieldValue := elem.Field(i)
|
||||
|
||||
field := elemTyp.Field(i)
|
||||
|
||||
// embed any fields from other structs.
|
||||
if indirectType(field.Type).Kind() == reflect.Struct && !structFieldIgnored(field) {
|
||||
fields = append(fields, lookupFields(fieldValue, skipUnexported, onlyZeros, append(parentIndex, i))...)
|
||||
continue
|
||||
if indirectType(field.Type).Kind() == reflect.Struct {
|
||||
if structFieldIgnored(field) {
|
||||
stateless++ // don't skip the loop yet, e.g. iris.Context.
|
||||
} else {
|
||||
structFields, statelessN := lookupFields(fieldValue, skipUnexported, onlyZeros, append(parentIndex, i))
|
||||
stateless += statelessN
|
||||
fields = append(fields, structFields...)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if onlyZeros && !isZero(fieldValue) {
|
||||
@@ -144,7 +156,7 @@ func lookupFields(elem reflect.Value, skipUnexported bool, onlyZeros bool, paren
|
||||
}
|
||||
|
||||
func lookupNonZeroFieldValues(elem reflect.Value) (nonZeroFields []reflect.StructField) {
|
||||
fields := lookupFields(elem, true, false, nil)
|
||||
fields, _ := lookupFields(elem, true, false, nil)
|
||||
for _, f := range fields {
|
||||
if fieldVal := elem.FieldByIndex(f.Index); goodVal(fieldVal) && !isZero(fieldVal) {
|
||||
/* && f.Type.Kind() == reflect.Ptr &&*/
|
||||
|
||||
Reference in New Issue
Block a user