示例#1
0
文件: replace.go 项目: get3w/get3w
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
	}
}
示例#2
0
文件: output.go 项目: get3w/get3w
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
}
示例#3
0
文件: join.go 项目: 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)
}
示例#4
0
文件: debug.go 项目: 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, ", ") + ")")
}
示例#5
0
文件: append.go 项目: get3w/get3w
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
	}
}