Ejemplo n.º 1
0
func (rr *retrieveResult) collectFields(rval reflect.Value, fields []string, content *types.ObjectContent) []types.ManagedObjectReference {
	var refs []types.ManagedObjectReference

	for _, name := range fields {
		val, err := fieldValue(rval, name)
		if err == nil {
			if rr.recurse[name] {
				refs = append(refs, fieldRefs(val)...)
			}

			prop := types.DynamicProperty{
				Name: name,
				Val:  val,
			}

			content.PropSet = append(content.PropSet, prop)
			continue
		}

		switch err {
		case errEmptyField:
			// ok
		case errMissingField:
			content.MissingSet = append(content.MissingSet, types.MissingProperty{
				Path: name,
				Fault: types.LocalizedMethodFault{Fault: &types.InvalidProperty{
					Name: name,
				}},
			})
		}
	}

	return refs
}
Ejemplo n.º 2
0
func (rr *retrieveResult) collectAll(rval reflect.Value, rtype reflect.Type, content *types.ObjectContent) {
	for i := 0; i < rval.NumField(); i++ {
		val := rval.Field(i)

		if isEmpty(val) {
			continue
		}

		f := rtype.Field(i)

		if f.Anonymous {
			// recurse into embedded field
			rr.collectAll(val, f.Type, content)
			continue
		}

		content.PropSet = append(content.PropSet, types.DynamicProperty{
			Name: lcFirst(f.Name),
			Val:  fieldValueInterface(f, val),
		})
	}
}