summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2016-11-29 20:53:06 +0100
committerSilvan Jegen <s.jegen@gmail.com>2016-11-29 20:53:06 +0100
commitdaa631dbb2891b6fb88357c4e6e5750bf4ed6e70 (patch)
treef89388a16562efcb68a6cdd3ea4899c4571714da
parent0175c3063667542f25179c050813cf2b391bba54 (diff)
Do something in the StringFilter
-rw-r--r--manager.go29
1 files changed, 27 insertions, 2 deletions
diff --git a/manager.go b/manager.go
index 91933f9..b6b41fb 100644
--- a/manager.go
+++ b/manager.go
@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
+ "strings"
)
type Manager struct {
@@ -28,7 +29,8 @@ type Filter interface {
}
type StringFilter struct {
- retchan chan *Work
+ retchan chan *Work
+ FilterFuncMap map[string]func(string) string
}
type Output interface {
@@ -67,6 +69,10 @@ func (i *StdinInput) Start() chan *Work {
func (f *StringFilter) Filter(ic chan *Work) chan *Work {
f.retchan = make(chan *Work, 100)
+ if f.FilterFuncMap == nil {
+ f.FilterFuncMap = make(map[string]func(string) string, 10)
+ f.FilterFuncMap["F"] = func(s string) string { return strings.ToUpper(s) }
+ }
go func() {
for w := range ic {
@@ -84,7 +90,26 @@ func (f *StringFilter) Filter(ic chan *Work) chan *Work {
w.err = err
}
- fmt.Printf("jm: %v\n", jm)
+ changed := false
+ for k, v := range jm {
+ ff, ok := f.FilterFuncMap[k]
+ if !ok {
+ continue
+ }
+
+ jm[k] = ff(v)
+ changed = true
+ }
+ if changed {
+ bs, err := json.Marshal(jm)
+ if err != nil {
+ fmt.Printf("Error when marshalling JSON: %q\n", err)
+ w.err = err
+ } else {
+ w.data = bs
+ }
+ }
+
f.retchan <- w
}
close(f.retchan)