Skip to content

Commit

Permalink
FEATURE/MAJOR: simple parsers: add them to go generate
Browse files Browse the repository at this point in the history
  • Loading branch information
oktalz committed Feb 15, 2019
1 parent 0fc63c1 commit 10cf1a8
Show file tree
Hide file tree
Showing 75 changed files with 2,517 additions and 1,125 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -2,4 +2,4 @@ config-parser
test/run_haproxy_locally
test/test
test/main.go
.vscode/launch.json
.vscode/
7 changes: 6 additions & 1 deletion errors/parse.go
Expand Up @@ -18,7 +18,12 @@ func (e *ParseError) Error() string {

var FetchError error = errors.New("no data")

var IndexOutOfRange error = errors.New("index out of range")

var InvalidData error = errors.New("invalid data")

var ParserMissingErr error = errors.New("parser missing")

var SectionMissingErr error = errors.New("section missing")
var SectionAlreadyExistsErr error = errors.New("section already exists")

var SectionMissingErr error = errors.New("section missing")
24 changes: 14 additions & 10 deletions parser.go
Expand Up @@ -125,7 +125,11 @@ func (p *Parser) SectionsCreate(sectionType Section, sectionName string) error {
}

//Set sets attribute from defaults section, can be nil to disable/remove
func (p *Parser) Set(sectionType Section, sectionName string, attribute string, data common.ParserData) error {
func (p *Parser) Set(sectionType Section, sectionName string, attribute string, data common.ParserData, index ...int) error {
setIndex := -1
if len(index) > 0 && index[0] > -1 {
setIndex = index[0]
}
st, ok := p.Parsers[sectionType]
if !ok {
return errors.SectionMissingErr
Expand All @@ -134,7 +138,7 @@ func (p *Parser) Set(sectionType Section, sectionName string, attribute string,
if !ok {
return fmt.Errorf("Section [%s] not found", sectionName)
}
return section.Set(attribute, data)
return section.Set(attribute, data, setIndex)
}

//HasParser checks if we have a parser for attribute
Expand Down Expand Up @@ -274,63 +278,63 @@ func (p *Parser) ProcessLine(line string, parts, previousParts []string, comment
config.Active = *config.Global
}
if config.State == "frontend" {
parserSectionName := parser.(*extra.SectionName)
parserSectionName := parser.(*extra.Section)
rawData, _ := parserSectionName.Get(false)
data := rawData.(*types.Section)
config.Frontend = getFrontendParser()
p.Parsers[Frontends][data.Name] = config.Frontend
config.Active = *config.Frontend
}
if config.State == "backend" {
parserSectionName := parser.(*extra.SectionName)
parserSectionName := parser.(*extra.Section)
rawData, _ := parserSectionName.Get(false)
data := rawData.(*types.Section)
config.Backend = getBackendParser()
p.Parsers[Backends][data.Name] = config.Backend
config.Active = *config.Backend
}
if config.State == "listen" {
parserSectionName := parser.(*extra.SectionName)
parserSectionName := parser.(*extra.Section)
rawData, _ := parserSectionName.Get(false)
data := rawData.(*types.Section)
config.Listen = getListenParser()
p.Parsers[Listen][data.Name] = config.Listen
config.Active = *config.Listen
}
if config.State == "resolvers" {
parserSectionName := parser.(*extra.SectionName)
parserSectionName := parser.(*extra.Section)
rawData, _ := parserSectionName.Get(false)
data := rawData.(*types.Section)
config.Resolver = getResolverParser()
p.Parsers[Resolvers][data.Name] = config.Resolver
config.Active = *config.Resolver
}
if config.State == "userlist" {
parserSectionName := parser.(*extra.SectionName)
parserSectionName := parser.(*extra.Section)
rawData, _ := parserSectionName.Get(false)
data := rawData.(*types.Section)
config.Userlist = getUserlistParser()
p.Parsers[UserList][data.Name] = config.Userlist
config.Active = *config.Userlist
}
if config.State == "peers" {
parserSectionName := parser.(*extra.SectionName)
parserSectionName := parser.(*extra.Section)
rawData, _ := parserSectionName.Get(false)
data := rawData.(*types.Section)
config.Peers = getPeersParser()
p.Parsers[Peers][data.Name] = config.Peers
config.Active = *config.Peers
}
if config.State == "mailers" {
parserSectionName := parser.(*extra.SectionName)
parserSectionName := parser.(*extra.Section)
rawData, _ := parserSectionName.Get(false)
data := rawData.(*types.Section)
config.Mailers = getMailersParser()
p.Parsers[Mailers][data.Name] = config.Mailers
config.Active = *config.Mailers
}
if config.State == "cache" {
parserSectionName := parser.(*extra.SectionName)
parserSectionName := parser.(*extra.Section)
rawData, _ := parserSectionName.Get(false)
data := rawData.(*types.Section)
config.Cache = getCacheParser()
Expand Down
15 changes: 11 additions & 4 deletions parsers/balance_autogenerated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 39 additions & 9 deletions parsers/bind_autogenerated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 39 additions & 9 deletions parsers/cpu-map_autogenerated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions parsers/daemon_autogenerated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 10cf1a8

Please sign in to comment.