Example #1
0
func (r *ReplaceFilter) Replace(input interface{}, data map[string]interface{}) interface{} {
	target := core.ToBytes(r.target.Resolve(data))
	with := core.ToBytes(r.with.Resolve(data))

	switch typed := input.(type) {
	case string:
		return strings.Replace(typed, string(target), string(with), r.count)
	case []byte:
		return bytes.Replace(typed, target, with, r.count)
	default:
		return input
	}
}
Example #2
0
func (o *Output) Execute(writer io.Writer, data map[string]interface{}) core.ExecuteState {
	value := o.Value.Resolve(data)
	if o.Filters != nil {
		for _, filter := range o.Filters {
			value = filter(value, data)
		}
	}
	writer.Write(core.ToBytes(value))
	return core.Normal
}
Example #3
0
File: join.go Project: get3w/get3w
// join elements of the array with certain character between them
func (f *JoinFilter) Join(input interface{}, data map[string]interface{}) interface{} {
	value := reflect.ValueOf(input)
	kind := value.Kind()
	if kind != reflect.Array && kind != reflect.Slice {
		return input
	}
	l := value.Len()
	if l == 0 {
		return input
	}

	array := make([][]byte, l)
	for i := 0; i < l; i++ {
		array[i] = core.ToBytes(value.Index(i).Interface())
	}

	glue := core.ToBytes(f.glue.Resolve(data))
	return bytes.Join(array, glue)
}
Example #4
0
File: debug.go Project: get3w/get3w
func (f *DebugFilter) Debug(input interface{}, data map[string]interface{}) interface{} {
	l := len(f.parameters)
	if l == 0 {
		return []byte("debug(" + input.(string) + ")")
	}
	values := make([]string, l)
	for i := 0; i < l; i++ {
		values[i] = string(core.ToBytes(f.parameters[i].Resolve(data)))
	}
	return []byte("debug(" + input.(string) + ", " + strings.Join(values, ", ") + ")")
}
Example #5
0
func (a *AppendFilter) Append(input interface{}, data map[string]interface{}) interface{} {
	var value string
	switch typed := a.value.Resolve(data).(type) {
	case string:
		value = typed
	default:
		value = string(core.ToBytes(typed))
	}
	switch typed := input.(type) {
	case string:
		return typed + value
	default:
		return core.ToString(input) + value
	}
}