summaryrefslogtreecommitdiff
path: root/types.go
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2016-12-09 21:12:18 +0100
committerSilvan Jegen <s.jegen@gmail.com>2016-12-09 21:12:18 +0100
commit26412f3077698dabcdbdf6a6e40276c56a6f74b5 (patch)
treec10ed9b5dbe3612da22247ec6c5afcd1879495eb /types.go
parent70299d51aeb8dc53a15eb06d46d4d2419619fd47 (diff)
Reorganize files
Diffstat (limited to 'types.go')
-rw-r--r--types.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/types.go b/types.go
new file mode 100644
index 0000000..abd2658
--- /dev/null
+++ b/types.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "fmt"
+ "sync"
+
+ "github.com/Shugyousha/stasher/work"
+)
+
+type Input interface {
+ Start() chan *work.Work
+}
+
+type Filter interface {
+ Filter(*work.Work) *work.Work
+}
+
+type Output interface {
+ Output(*work.Work)
+}
+
+type Manager struct {
+ Input Input
+ Filter Filter
+ Output Output
+}
+
+func (m *Manager) Run() {
+ var wg sync.WaitGroup
+
+ ic := m.Input.Start()
+ for w := range ic {
+ wg.Add(1)
+
+ go func(w *work.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()
+ }(w)
+ }
+
+ wg.Wait()
+}