diff options
author | 2018-01-07 14:51:32 -0500 | |
---|---|---|
committer | 2018-01-07 14:51:32 -0500 | |
commit | c59f5f6e86e1d041a9aa7b324b90582b3a4b277a (patch) | |
tree | c8091f7101125f066d5bc59c20dbf6b4b192311d /plugin/pkg/fall/fall.go | |
parent | c6febe6250361eee580dbb8a601a444f23ed7ac2 (diff) | |
download | coredns-c59f5f6e86e1d041a9aa7b324b90582b3a4b277a.tar.gz coredns-c59f5f6e86e1d041a9aa7b324b90582b3a4b277a.tar.zst coredns-c59f5f6e86e1d041a9aa7b324b90582b3a4b277a.zip |
Simplify plugin/pkg/fall (#1358)
* Simplify plugin/pkg/fall
* Remove unused import
* Fix fall_test
* Get fall coverage to 100% just because
* gofmt. sigh.
Diffstat (limited to 'plugin/pkg/fall/fall.go')
-rw-r--r-- | plugin/pkg/fall/fall.go | 79 |
1 files changed, 30 insertions, 49 deletions
diff --git a/plugin/pkg/fall/fall.go b/plugin/pkg/fall/fall.go index 99ad34618..adecc4c89 100644 --- a/plugin/pkg/fall/fall.go +++ b/plugin/pkg/fall/fall.go @@ -7,71 +7,52 @@ import ( // F can be nil to allow for no fallthrough, empty allow all zones to fallthrough or // contain a zone list that is checked. -type F []string - -// New returns a new F. -func New() *F { return new(F) } +type F struct { + Zones []string +} // Through will check if we should fallthrough for qname. Note that we've named the // variable in each plugin "Fall", so this then reads Fall.Through(). -func (f *F) Through(qname string) bool { - if f == nil { - return false - } - if len(*f) == 0 { - return true - } - zone := plugin.Zones(*f).Matches(qname) - return zone != "" +func (f F) Through(qname string) bool { + return plugin.Zones(f.Zones).Matches(qname) != "" } -// SetZones will set zones in f. -func (f *F) SetZones(zones []string) { +// setZones will set zones in f. +func (f *F) setZones(zones []string) { for i := range zones { zones[i] = plugin.Host(zones[i]).Normalize() } - *f = zones + f.Zones = zones } -// Example returns an F with example.org. as the zone name. -var Example = func() *F { - f := F([]string{"example.org."}) - return &f -}() - -// Zero returns a zero valued F. -var Zero = func() *F { - f := F([]string{}) - return &f -} - -// IsNil returns true is f is nil. -func (f *F) IsNil() bool { return f == nil } - -// IsZero returns true is f is zero (and not nil). -func (f *F) IsZero() bool { - if f == nil { - return false +// SetZonesFromArgs sets zones in f to the passed value or to "." if the slice is empty. +func (f *F) SetZonesFromArgs(zones []string) { + if len(zones) == 0 { + f.setZones(Root().Zones) + return } - return len(*f) == 0 + f.setZones(zones) } -// Equal returns true if f and g are equal. Only useful in tests, The (possible) zones -// are *not* checked. -func (f *F) Equal(g *F) bool { - if f.IsNil() { - if g.IsNil() { - return true - } +// Equal returns true if f and g are equal. +func (f F) Equal(g F) bool { + if len(f.Zones) != len(g.Zones) { return false } - if f.IsZero() { - if g.IsZero() { - return true + for i := range f.Zones { + if f.Zones[i] != g.Zones[i] { + return false } } - if len(*f) != len(*g) { - return false - } return true } + +// Zero returns a zero valued F. +var Zero = func() F { + return F{[]string{}} +} + +// Root returns F set to only ".". +var Root = func() F { + return F{[]string{"."}} +} |