func extractPropertyValue()

in pkg/confidence/utils.go [24:41]


func extractPropertyValue(path string, values map[string]interface{}) (interface{}, error) {
	if path == "" {
		return values, nil
	}

	firstPartAndRest := strings.SplitN(path, ".", 2)
	if len(firstPartAndRest) == 1 {
		value := values[firstPartAndRest[0]]
		return value, nil
	}

	childMap, ok := values[firstPartAndRest[0]].(map[string]interface{})
	if ok {
		return extractPropertyValue(firstPartAndRest[1], childMap)
	}

	return false, fmt.Errorf("unable to find property in path %s", path)
}