Adding capability to filter by name, id or status to list containers api

Closes #7599

Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
This commit is contained in:
Srini Brahmaroutu 2014-10-13 06:12:44 +00:00
parent 9ac922face
commit ab81bfc8f5

View file

@ -3,6 +3,7 @@ package filters
import (
"encoding/json"
"errors"
"regexp"
"strings"
)
@ -61,3 +62,22 @@ func FromParam(p string) (Args, error) {
}
return args, nil
}
func (filters Args) Match(field, source string) bool {
fieldValues := filters[field]
//do not filter if there is no filter set or cannot determine filter
if len(fieldValues) == 0 {
return true
}
for _, name2match := range fieldValues {
match, err := regexp.MatchString(name2match, source)
if err != nil {
continue
}
if match {
return true
}
}
return false
}