Skip to content

Commit

Permalink
move validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CAFxX committed Jan 21, 2021
1 parent 3a25b3d commit 6e47e76
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ func Adapter(opts ...Option) (func(http.Handler) http.Handler, error) {
}
}

if err := c.validate(); err != nil {
return nil, err
}

bufPool := &sync.Pool{}
writerPool := &sync.Pool{}

Expand Down Expand Up @@ -131,27 +127,16 @@ type comp struct {
priority int
}

func (c *config) validate() error {
if c.minSize < 0 {
return fmt.Errorf("minimum size can not be negative: %d", c.minSize)
}

switch c.prefer {
case PreferServer, PreferClient:
default:
return fmt.Errorf("invalid prefer config: %v", c.prefer)
}

return nil
}

// Option can be passed to Handler to control its configuration.
type Option func(c *config) error

// MinSize is an option that controls the minimum size of payloads that
// should be compressed. The default is DefaultMinSize.
func MinSize(size int) Option {
return func(c *config) error {
if size < 0 {
return fmt.Errorf("minimum size can not be negative: %d", size)
}
c.minSize = size
return nil
}
Expand Down

0 comments on commit 6e47e76

Please sign in to comment.