diff options
author | Silvan Jegen <s.jegen@gmail.com> | 2017-01-20 21:03:08 +0100 |
---|---|---|
committer | Silvan Jegen <s.jegen@gmail.com> | 2017-01-20 21:03:08 +0100 |
commit | 5c24009f2b1fd5a7e5abd4dc33ebdec0c6eaaf25 (patch) | |
tree | 7447a384efe6a5b45106fde621e53bdf38ad608a /input | |
parent | ba15251035961020363fa5aff95ff0a361023af9 (diff) |
Introduce registry
We introduce a registry that contains maps to builder functions. These
builder functions return the interface implementation of the modules
specified in the configuration.
We also make the input module type use the registry. All other module
types still have to be converted.
Diffstat (limited to 'input')
-rw-r--r-- | input/http/http.go (renamed from input/http.go) | 20 | ||||
-rw-r--r-- | input/inputinterface.go (renamed from input/interface.go) | 0 | ||||
-rw-r--r-- | input/stdin/stdin.go (renamed from input/stdin.go) | 10 |
3 files changed, 26 insertions, 4 deletions
diff --git a/input/http.go b/input/http/http.go index 285f1f6..71a0340 100644 --- a/input/http.go +++ b/input/http/http.go @@ -1,20 +1,36 @@ -package input +package http import ( "fmt" "io/ioutil" "net/http" + "github.com/Shugyousha/stasher/input" + "github.com/Shugyousha/stasher/registry" "github.com/Shugyousha/stasher/work" ) +func init() { + registry.Inputregistry["http"] = New +} + type HTTPInput struct { retchan chan *work.Work prefix string port string } -func NewHTTPInput(prefix, port string) *HTTPInput { +func New(conf map[string]string) input.Input { + prefix := conf["prefix"] + if prefix == "" { + fmt.Printf("Need a prefix when setting up http input\n") + return nil + } + port := conf["port"] + if port == "" { + fmt.Printf("Need a port number when setting up http input\n") + return nil + } return &HTTPInput{prefix: prefix, port: port} } diff --git a/input/interface.go b/input/inputinterface.go index 1743249..1743249 100644 --- a/input/interface.go +++ b/input/inputinterface.go diff --git a/input/stdin.go b/input/stdin/stdin.go index 25840ef..fa4d21f 100644 --- a/input/stdin.go +++ b/input/stdin/stdin.go @@ -1,4 +1,4 @@ -package input +package stdin import ( "bufio" @@ -6,14 +6,20 @@ import ( "io" "os" + "github.com/Shugyousha/stasher/input" + "github.com/Shugyousha/stasher/registry" "github.com/Shugyousha/stasher/work" ) +func init() { + registry.Inputregistry["input"] = New +} + type StdinInput struct { retchan chan *work.Work } -func NewStdin() *StdinInput { +func New(map[string]string) input.Input { return &StdinInput{} } |