Update files based on go lint

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-09-29 16:03:09 -04:00
parent 70b353dff2
commit f43b7acfd2
22 changed files with 61 additions and 44 deletions

View File

@@ -8,8 +8,10 @@ type Adaptor interface {
Field(fieldpath []string) (value string, present bool)
}
// AdapterFunc allows implementation specific matching of fieldpaths
type AdapterFunc func(fieldpath []string) (string, bool)
// Field returns the field name and true if it exists
func (fn AdapterFunc) Field(fieldpath []string) (string, bool) {
return fn(fieldpath)
}

View File

@@ -58,22 +58,28 @@ import (
"github.com/containerd/containerd/log"
)
// Filter matches specific resources based the provided filter
type Filter interface {
Match(adaptor Adaptor) bool
}
// FilterFunc is a function that handles matching with an adaptor
type FilterFunc func(Adaptor) bool
// Match matches the FilterFunc returning true if the object matches the filter
func (fn FilterFunc) Match(adaptor Adaptor) bool {
return fn(adaptor)
}
// Always is a filter that always returns true for any type of object
var Always FilterFunc = func(adaptor Adaptor) bool {
return true
}
// Any allows multiple filters to be matched aginst the object
type Any []Filter
// Match returns true if any of the provided filters are true
func (m Any) Match(adaptor Adaptor) bool {
for _, m := range m {
if m.Match(adaptor) {
@@ -84,8 +90,10 @@ func (m Any) Match(adaptor Adaptor) bool {
return false
}
// All allows multiple filters to be matched aginst the object
type All []Filter
// Match only returns true if all filters match the object
func (m All) Match(adaptor Adaptor) bool {
for _, m := range m {
if !m.Match(adaptor) {

View File

@@ -243,10 +243,9 @@ func TestFilters(t *testing.T) {
}
return
} else {
if err != nil {
t.Fatal(err)
}
}
if err != nil {
t.Fatal(err)
}
if filter == nil {

View File

@@ -67,9 +67,8 @@ func (s *scanner) next() rune {
if r == utf8.RuneError {
if w > 0 {
return tokenIllegal
} else {
return tokenEOF
}
return tokenEOF
}
if r == 0 {