github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/state/paginator/filter.go (about) 1 package paginator 2 3 // Filter is the interface that must be implemented to skip values when using 4 // the Paginator. 5 type Filter interface { 6 // Evaluate returns true if the element should be added to the page. 7 Evaluate(interface{}) (bool, error) 8 } 9 10 // GenericFilter wraps a function that can be used to provide simple or in 11 // scope filtering. 12 type GenericFilter struct { 13 Allow func(interface{}) (bool, error) 14 } 15 16 func (f GenericFilter) Evaluate(raw interface{}) (bool, error) { 17 return f.Allow(raw) 18 } 19 20 // NamespaceFilter skips elements with a namespace value that is not in the 21 // allowable set. 22 type NamespaceFilter struct { 23 AllowableNamespaces map[string]bool 24 } 25 26 func (f NamespaceFilter) Evaluate(raw interface{}) (bool, error) { 27 if raw == nil { 28 return false, nil 29 } 30 31 item, _ := raw.(NamespaceGetter) 32 namespace := item.GetNamespace() 33 34 if f.AllowableNamespaces == nil { 35 return true, nil 36 } 37 if f.AllowableNamespaces[namespace] { 38 return true, nil 39 } 40 return false, nil 41 }