func digStruct()

in pkg/internal/expression/value_type.go [33:64]


func digStruct(value reflect.Value, key string) (any, error) {
	for i := 0; i < value.Type().NumField(); i += 1 {
		structField := value.Type().Field(i)
		if !structField.IsExported() {
			continue
		}

		if structField.Anonymous {
			res, err := DigObject(value.FieldByIndex(structField.Index).Interface(), key)
			if err == nil {
				return res, nil
			}
		}

		fieldName := structField.Name

		if tag, ok := structField.Tag.Lookup("json"); ok {
			if tag == "-" {
				continue
			}
			tagName, _, _ := strings.Cut(tag, ",")
			if tagName != "" {
				fieldName = tagName
			}
		}

		if fieldName == key {
			return value.FieldByIndex(structField.Index).Interface(), nil
		}
	}
	return nil, fmt.Errorf("the %q was not found", key)
}