Esempio n. 1
0
File: config.go Progetto: pirater/os
func (c *CloudConfig) Merge(values map[interface{}]interface{}) (*CloudConfig, error) {
	d := map[interface{}]interface{}{}
	if err := util.Convert(c, &d); err != nil {
		return c, err
	}
	r := util.MapsUnion(d, StringifyValues(values))
	t := &CloudConfig{}
	if err := util.Convert(r, t); err != nil {
		return c, err
	}
	return t, nil
}
Esempio n. 2
0
func filterDottedKeys(data map[interface{}]interface{}, keys []string) (filtered, rest map[interface{}]interface{}) {
	filtered = map[interface{}]interface{}{}
	rest = util.MapCopy(data)

	for _, key := range keys {
		f, r := filterKey(data, strings.Split(key, "."))
		filtered = util.MapsUnion(filtered, f)
		rest = util.MapsIntersection(rest, r)
	}

	return
}
Esempio n. 3
0
File: disk.go Progetto: pirater/os
func readConfig(bytes []byte, substituteMetadataVars bool, files ...string) (map[interface{}]interface{}, error) {
	// You can't just overlay yaml bytes on to maps, it won't merge, but instead
	// just override the keys and not merge the map values.
	left := make(map[interface{}]interface{})
	metadata := readMetadata()
	for _, file := range files {
		content, err := readConfigFile(file)
		if err != nil {
			return nil, err
		}
		if len(content) == 0 {
			continue
		}
		if substituteMetadataVars {
			content = substituteVars(content, metadata)
		}

		right := make(map[interface{}]interface{})
		err = yaml.Unmarshal(content, &right)
		if err != nil {
			return nil, err
		}

		left = util.MapsUnion(left, right)
	}

	if bytes != nil && len(bytes) > 0 {
		right := make(map[interface{}]interface{})
		if substituteMetadataVars {
			bytes = substituteVars(bytes, metadata)
		}
		if err := yaml.Unmarshal(bytes, &right); err != nil {
			return nil, err
		}

		left = util.MapsUnion(left, right)
	}

	return left, nil
}