Example #1
0
func makePluginPair(plugin string, data *gabs.Container) PluginData {
	if s, ok := data.Data().(string); ok {
		obj := gabs.New()
		ns := strings.Split(plugin, ".")
		obj.Set(s, ns[len(ns)-1])
		data = obj
	} else {
		var cpy interface{}
		bs, _ := json.Marshal(data.Data())
		json.Unmarshal(bs, &cpy)
		data.Set(cpy)
	}

	return PluginData{plugin, PluginRegestry.Get(plugin), Manifest{data}}
}
Example #2
0
func includeFile(file string, tree *gabs.Container) error {
	loaded, err := loader.LoadFile(file)
	if err != nil {
		return err
	}

	log.Println("include:", file)

	merged, err := mergemap.Merge(loaded.Data().(map[string]interface{}), tree.Data().(map[string]interface{}))
	if err != nil {
		return err
	}

	_, err = tree.Set(merged)
	return err
}
Example #3
0
func ProcessAll(tree *gabs.Container, visitor func(string, *gabs.Container, interface{}, interface{}) error) error {
	errors := make([]string, 0)

	if _, ok := tree.Data().(map[string]interface{}); ok {
		mmap, _ := tree.ChildrenMap()
		for k, v := range mmap {
			if err := ProcessAll(v, visitor); err != nil {
				errors = append(errors, err.Error())
				continue
			}

			if err := visitor("map", tree, v.Data(), k); err != nil {
				errors = append(errors, err.Error())
			}
		}
	} else if _, ok := tree.Data().([]interface{}); ok {
		marray, _ := tree.Children()
		for i, v := range marray {
			if err := ProcessAll(v, visitor); err != nil {
				errors = append(errors, err.Error())
				continue
			}

			if err := visitor("array", tree, v.Data(), i); err != nil {
				errors = append(errors, err.Error())
			}
		}
	} else {
		if err := visitor("other", tree, tree.Data(), nil); err != nil {
			errors = append(errors, err.Error())
		}
	}

	if len(errors) == 0 {
		return nil
	} else {
		return fmt.Errorf(strings.Join(errors, "\n"))
	}
}