func normalizeMapKeyToCamelCase()

in agent/envoy_bootstrap/envoy_bootstrap.go [363:387]


func normalizeMapKeyToCamelCase(m map[string]interface{}, key string) (map[string]interface{}, error) {
	// This function will normalize the input `m` map[string]interface{} to contain only the lowerCamelCase format of
	// the input `key`. The input `m` map[string]interface{} can contain the key either as lowerCamelCase or as
	// snake_case type. But if it contains both case type for the same `key` then this function will throw an error.
	// Eg: If 'statsConfig' is the key then `m` cannot contain both 'statsConfig' & 'stats_config'.
	key_in_snake_case := strcase.SnakeCase(key)
	keyInLowerCamelCase := strcase.LowerCamelCase(key)
	if key_in_snake_case == keyInLowerCamelCase {
		// Input contains a single word where snake_case and camelCase string are the same. Eg: tracing.
		return m, nil
	}
	if _, ok := m[key_in_snake_case]; !ok {
		// Nothing to normalize.
		return m, nil
	}
	if _, ok := m[keyInLowerCamelCase]; ok {
		return nil, fmt.Errorf("the config contains both %s(lowerCamelCase) & "+
			"%s(snake_case), specify only one of them\n", keyInLowerCamelCase, key_in_snake_case)
	} else {
		// If snake_case is used in input `m`, convert that to lowerCamelCase.
		m[keyInLowerCamelCase] = m[key_in_snake_case]
		delete(m, key_in_snake_case)
	}
	return m, nil
}