diff options
author | Silvan Jegen <s.jegen@gmail.com> | 2017-02-16 03:28:01 +0100 |
---|---|---|
committer | Silvan Jegen <s.jegen@gmail.com> | 2017-02-16 03:28:01 +0100 |
commit | 6f82a101fbfe6a040bed68c107e1f66012b0dbab (patch) | |
tree | 757f6d4d7c6b9e74bdcd20e3d6e75f3b5a237367 | |
parent | 5147048d4a67c59f799203e1cc5f79b183208cab (diff) |
Return a Manager, not a Config
We are not using the manager yet though.
-rw-r--r-- | conf/parser.go | 25 | ||||
-rw-r--r-- | 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) { @@ -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) } |