// newReference returns a new MOR, where Type defaults to type of the given item // and Value defaults to a unique id for the given type. func (r *Registry) newReference(item mo.Reference) types.ManagedObjectReference { ref := item.Reference() if ref.Type == "" { ref.Type = TypeName(item) } if ref.Value == "" { r.counter++ ref.Value = fmt.Sprintf("%s-%d", strings.ToLower(ref.Type), r.counter) } return ref }
func (r *Registry) Put(item mo.Reference) mo.Reference { r.m.Lock() defer r.m.Unlock() ref := item.Reference() if ref.Type == "" || ref.Value == "" { ref = r.newReference(item) // mo.Reference() returns a value, not a pointer so use reflect to set the Self field reflect.ValueOf(item).Elem().FieldByName("Self").Set(reflect.ValueOf(ref)) } r.objects[ref] = item return item }