Skip to content

Commit 8958266

Browse files
committed
added GetParserFromType and GetSourceFromType to allow more elegant api usage outside this project
1 parent 6807afb commit 8958266

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

parsers/parser.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
package parsers
22

3-
import "github.com/EffnerApp/subparser/model"
3+
import (
4+
"errors"
5+
"github.com/EffnerApp/subparser/model"
6+
)
47

58
type Parser interface {
69
Parse(content string) ([]*model.Plan, error)
710
}
11+
12+
func GetParserFromType(parserType string) (Parser, error) {
13+
switch parserType {
14+
case "effner":
15+
return &EffnerDSBParser{}, nil
16+
case "effner-de":
17+
return &EffnerDEParser{}, nil
18+
default:
19+
return nil, errors.New("unknown parser type '" + parserType + "'")
20+
}
21+
}

source/source.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
package source
22

3+
import "errors"
4+
35
type Source interface {
46
Load() (string, error)
57
}
8+
9+
func GetSourceFromType(sourceType string, user string, pass string, path string) (Source, error) {
10+
switch sourceType {
11+
case "dsb":
12+
return &DSBSource{
13+
User: user,
14+
Pass: pass,
15+
}, nil
16+
case "file":
17+
return &FileSource{
18+
Path: path,
19+
}, nil
20+
case "effner":
21+
return &EffnerDESource{
22+
Password: pass,
23+
}, nil
24+
default:
25+
return nil, errors.New("unknown source type '" + sourceType + "'")
26+
}
27+
}

0 commit comments

Comments
 (0)