From 6f82a101fbfe6a040bed68c107e1f66012b0dbab Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Thu, 16 Feb 2017 03:28:01 +0100 Subject: Return a Manager, not a Config We are not using the manager yet though. --- conf/parser.go | 25 ++++++++++++++++++------- main.go | 4 ++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/conf/parser.go b/conf/parser.go index 29f8968..b1b4447 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -21,7 +21,10 @@ import ( "io" "os" + "github.com/Shugyousha/stasher/filter" + "github.com/Shugyousha/stasher/input" "github.com/Shugyousha/stasher/manager" + "github.com/Shugyousha/stasher/output" "github.com/Shugyousha/stasher/registry" ) @@ -48,12 +51,18 @@ func newParser(s *scanner) *parser { func NewManagerFromConfig(r io.Reader) *manager.Manager { p := newParser(newScanner(r)) - p.startparsing() - return &manager.Manager{} + return p.parse() } -func (p *parser) startparsing() { +func (p *parser) parse() *manager.Manager { + var ( + in input.Input + filt filter.Filter + out output.Output + ) + + // TODO: use a loop to parse all the main modules? inputmdescs := p.mainmodule("input") fmt.Fprintf(os.Stderr, "input moduledescs: %#v\n", inputmdescs) for _, idesc := range inputmdescs { @@ -61,7 +70,7 @@ func (p *parser) startparsing() { if !ok { fmt.Fprintf(os.Stderr, "input module is not known: %q\n", idesc.name) } - inputnewfunc(nil) + in = inputnewfunc(idesc.keyvalues) } filtermdescs := p.mainmodule("filter") @@ -71,18 +80,20 @@ func (p *parser) startparsing() { if !ok { fmt.Fprintf(os.Stderr, "filter module is not known: %q\n", fdesc.name) } - filternewfunc(nil) + filt = filternewfunc(nil) } outputmdescs := p.mainmodule("output") fmt.Fprintf(os.Stderr, "output moduledescs: %#v\n", outputmdescs) for _, odesc := range outputmdescs { - filternewfunc, ok := registry.Outputregistry[odesc.name] + outputnewfunc, ok := registry.Outputregistry[odesc.name] if !ok { fmt.Fprintf(os.Stderr, "output module is not known: %q\n", odesc.name) } - filternewfunc(nil) + out = outputnewfunc(nil) } + + return &manager.Manager{Input: in, Filter: filt, Output: out} } func (p *parser) advanceOneToken(place string) { diff --git a/main.go b/main.go index 8b2248a..8295ea3 100644 --- a/main.go +++ b/main.go @@ -20,8 +20,8 @@ func main() { os.Exit(1) } - c := conf.NewManagerFromConfig(bufio.NewReader(f)) - fmt.Fprintf(os.Stderr, "config: %#v\n", c) + man := conf.NewManagerFromConfig(bufio.NewReader(f)) + fmt.Fprintf(os.Stderr, "manager: %#v\n", man) ffmap := make(map[string]func(string) string, 10) ffmap["F"] = func(s string) string { return strings.ToUpper(s) } -- cgit v1.2.3