Ejemplo n.º 1
0
// trimFunc - Runs strings.TrimSpace on strings, lists and maps.
func trimFunc(in action.Format) interface{} {
	// If it's a string just trim
	if value, ok := in.String(); ok {
		return strings.TrimSpace(value)
	}

	// If it's a list - deep trim all values
	if value, ok := in.List(); ok {
		for num, val := range value {
			if result := trimFunc(action.Format{Value: val}); result != nil {
				value[num] = result
			}
		}
		return value
	}

	// If it's a map - deep trim all values
	if value, ok := in.Map(); ok {
		value.Transform(value.Keys(), trimFunc)
		return value
	}

	// Not expected type - don't touch
	return in.Value
}