Skip to content

Commit

Permalink
chore: drop Quamina.flattenerSpecified
Browse files Browse the repository at this point in the history
Replace Quamina.flattenerSpecified with Quamina.flattener != nil.
The conversion required rewriting a bit of boolean logic;
but it stayed equivalent.
  • Loading branch information
arnehormann committed Jul 20, 2024
1 parent 6fb7cd4 commit 6bacfb3
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions quamina.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
type Quamina struct {
flattener Flattener
matcher matcher
flattenerSpecified bool
mediaTypeSpecified bool
deletionSpecified bool
}
Expand All @@ -25,7 +24,7 @@ type Option func(q *Quamina) error
// invocation of quamina.New() with the WithFlattener() option.
func WithMediaType(mediaType string) Option {
return func(q *Quamina) error {
if q.flattenerSpecified {
if q.flattener != nil {
return errors.New("flattener already specified")
}
if q.mediaTypeSpecified {
Expand All @@ -50,14 +49,13 @@ func WithFlattener(f Flattener) Option {
if q.mediaTypeSpecified {
return errors.New("media-type already specified")
}
if q.flattenerSpecified {
if q.flattener != nil {
return errors.New("flattener specified more than once")
}
if f == nil {
return errors.New("nil Flattener")
}
q.flattener = f
q.flattenerSpecified = true
return nil
}
}
Expand Down Expand Up @@ -101,7 +99,7 @@ func New(opts ...Option) (*Quamina, error) {
return nil, err
}
}
if !(q.mediaTypeSpecified || q.flattenerSpecified) {
if (!q.mediaTypeSpecified) && (q.flattener == nil) {
q.flattener = newJSONFlattener()
}
if !q.deletionSpecified {
Expand Down

0 comments on commit 6bacfb3

Please sign in to comment.