Skip to content

Commit

Permalink
BUG/MINOR: compression direction both not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
hdurand0710 committed Feb 20, 2024
1 parent c61df38 commit bd5c13c
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 1 deletion.
53 changes: 53 additions & 0 deletions parsers/compression-direction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2022 HAProxy Technologies
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package parsers

import (
"fmt"

"github.com/haproxytech/config-parser/v5/common"
"github.com/haproxytech/config-parser/v5/errors"
"github.com/haproxytech/config-parser/v5/types"
)

type CompressionDirection struct {
data *types.StringC
preComments []string // comments that appear before the actual line
}

func (c *CompressionDirection) Parse(line string, parts []string, comment string) (string, error) {
if len(parts) < 3 {
return "", &errors.ParseError{Parser: "CompressionDirection", Line: line, Message: "Parse error"}
}
c.data = &types.StringC{
Value: parts[2],
Comment: comment,
}
return "", nil
}

func (c *CompressionDirection) Result() ([]common.ReturnResultLine, error) {
if c.data == nil {
return nil, errors.ErrFetch
}
return []common.ReturnResultLine{
{
Data: fmt.Sprintf("compression direction %s", c.data.Value),
Comment: c.data.Comment,
},
}, nil
}
99 changes: 99 additions & 0 deletions parsers/compression-direction_generated.go

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

3 changes: 3 additions & 0 deletions section-parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (p *configParser) getDefaultParser() *Parsers {
addParser(parser, &sequence, &parsers.CompressionAlgo{})
addParser(parser, &sequence, &parsers.CompressionType{})
addParser(parser, &sequence, &parsers.CompressionOffload{})
addParser(parser, &sequence, &parsers.CompressionDirection{})
addParser(parser, &sequence, &parsers.DefaultServer{})
addParser(parser, &sequence, &parsers.LoadServerStateFromFile{})
addParser(parser, &sequence, &parsers.ErrorFile{})
Expand Down Expand Up @@ -566,6 +567,7 @@ func (p *configParser) getBackendParser() *Parsers {
addParser(parser, &sequence, &parsers.CompressionAlgo{})
addParser(parser, &sequence, &parsers.CompressionType{})
addParser(parser, &sequence, &parsers.CompressionOffload{})
addParser(parser, &sequence, &parsers.CompressionDirection{})
addParser(parser, &sequence, &tcp.Requests{})
addParser(parser, &sequence, &stats.Stats{Mode: "backend"})
addParser(parser, &sequence, &parsers.HTTPReuse{})
Expand Down Expand Up @@ -706,6 +708,7 @@ func (p *configParser) getListenParser() *Parsers {
addParser(parser, &sequence, &parsers.CompressionAlgo{})
addParser(parser, &sequence, &parsers.CompressionType{})
addParser(parser, &sequence, &parsers.CompressionOffload{})
addParser(parser, &sequence, &parsers.CompressionType{})
addParser(parser, &sequence, &tcp.Requests{})
addParser(parser, &sequence, &stats.Stats{Mode: "listen"})
addParser(parser, &sequence, &parsers.HTTPReuse{})
Expand Down
82 changes: 82 additions & 0 deletions tests/compression-direction_generated_test.go

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

6 changes: 5 additions & 1 deletion types/types-generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Int64C struct {
Comment string
}

// String is used by parsers Mode, DefaultBackend, SimpleTimeTwoWords, StatsTimeout
// String is used by parsers Mode, DefaultBackend, SimpleTimeTwoWords, StatsTimeout, CompressionDirection
//
//generate:type:Mode
//name:mode
Expand All @@ -100,6 +100,10 @@ type Int64C struct {
//name:log-send-hostname
//test:ok:log-send-hostname
//test:ok:log-send-hostname something
//generate:type:CompressionDirection
//name:compression direction
//test:ok:compression direction both
//test:fail:compression direction
type StringC struct {
Value string
Comment string
Expand Down

0 comments on commit bd5c13c

Please sign in to comment.