func()

in config/config_map.go [60:92]


func (c *ConfigMap) Insert(key string, value string) error {
	keys, err := parseKey(strings.ToLower(key))
	if err != nil {
		return err
	}

	currentMap := c.config
	lastIndex := len(keys) - 1
	for i, subKey := range keys {
		// If we are at the last key, set the value
		if i == lastIndex {
			v, err := parseValue(value)
			if err != nil {
				return err
			}

			currentMap[subKey] = v
		} else {
			// If the sub-map doesn't exist, create it
			if _, ok := currentMap[subKey]; !ok {
				currentMap[subKey] = make(map[string]interface{})
			}
			// Update the current map to the sub-map
			m, ok := currentMap[subKey].(map[string]interface{})
			if !ok {
				return fmt.Errorf("invalid key: '%s' - '%s' is already being used for a value", key, subKey)
			}
			currentMap = m
		}
	}

	return nil
}