diff options
Diffstat (limited to 'conf')
-rw-r--r-- | conf/parser.go | 25 |
1 files changed, 18 insertions, 7 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) { |