Пример #1
0
// Link indicates that the object at the given src path should be equal to the
// value at the given target path. All links are resolved when calling Finish
// so there are no ordering constraints on links.
func (loader *Loader) Link(src, target path.P) {
	klog.KPrintf("blueprint.loader.link.debug", "src=%s, target=%s", src, target)

	if loader.links == nil {
		loader.links = make(map[string]path.P)
	}

	loader.links[src.String()] = target
}
Пример #2
0
// Type asserts the type of an object at the given path.  This is useful when
// dealing with interfaces which can't be pathed through unless they're
// associated with a concrete type.
func (loader *Loader) Type(src path.P, name string) {
	klog.KPrintf("blueprint.loader.type.debug", "src=%s, name=%s", src, name)

	if value, ok := New(name); !ok {
		loader.ErrorAt(fmt.Errorf("unknown type '%s'", name), src)

	} else if err := src.Set(loader.Values, value); err != nil {
		loader.ErrorAt(err, src)
	}
}
Пример #3
0
// Add sets the object at the given path to value.
func (loader *Loader) Add(src path.P, value interface{}) {
	klog.KPrintf("blueprint.loader.add.debug", "src=%s, value={%T, %v}", src, value, value)

	err := src.Set(loader.Values, value)
	if err == nil {
		return
	}

	if err == path.ErrInvalidType {
		var typ reflect.Type
		if typ, err = src.Type(loader.Values); err == nil {
			if value, err = convert(typ, value); err == nil {
				err = src.Set(loader.Values, value)
			}
		}
	}

	loader.ErrorAt(err, src)
}