summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2016-12-04 18:55:12 +0100
committerSilvan Jegen <s.jegen@gmail.com>2016-12-04 18:55:12 +0100
commita36d51ebe5496334ce59a08d120ffc6f2169626f (patch)
treeac1f6ff554eb5fb3b24d17f706a8fc15cb9a5909
parenta8714895f5f99a4245fcdc5842e790fb21cd9aac (diff)
Introduce a New function for the StringFilter
-rw-r--r--manager.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/manager.go b/manager.go
index 470fbf3..ea1d15a 100644
--- a/manager.go
+++ b/manager.go
@@ -46,6 +46,10 @@ type Work struct {
err error
}
+func (w *Work) Error() error {
+ return w.err
+}
+
func (i *StdinInput) Start() chan *Work {
i.retchan = make(chan *Work, 100)
r := bufio.NewReader(os.Stdin)
@@ -68,6 +72,10 @@ func (i *StdinInput) Start() chan *Work {
return i.retchan
}
+func NewStringFilter(ffmap map[string]func(string) string) *StringFilter {
+ return &StringFilter{FilterFuncMap: ffmap}
+}
+
func (f *StringFilter) Filter(w *Work) *Work {
dec := json.NewDecoder(bytes.NewReader(w.data))
jm := make(map[string]string, 10)
@@ -119,6 +127,10 @@ func (m *Manager) Run() {
go func(w *Work) {
nw := m.Filter.Filter(w)
+ err := nw.Error()
+ if err != nil {
+ fmt.Printf("Got an error when processing Work: %q\n", err)
+ }
m.Output.Output(nw)
wg.Done()
@@ -134,7 +146,7 @@ func main() {
m := Manager{
Input: &StdinInput{},
- Filter: &StringFilter{FilterFuncMap: ffmap},
+ Filter: NewStringFilter(ffmap),
Output: &StdoutOutput{},
}