4 "github.com/vapor/errors"
8 errMissingFilterKey = errors.New("missing filter key")
9 errInvalidFilterType = errors.New("invalid filter type")
12 // Display defines how the data is displayed
14 Filter map[string]interface{} `json:"filter"`
15 Sorter Sorter `json:"sort"`
20 Order string `json:"order"`
23 // GetFilterString give the filter keyword return the string value
24 func (d *Display) GetFilterString(filterKey string) (string, error) {
25 if _, ok := d.Filter[filterKey]; !ok {
26 return "", errMissingFilterKey
28 switch val := d.Filter[filterKey].(type) {
32 return "", errInvalidFilterType
35 // GetFilterNum give the filter keyword return the numeric value
36 func (d *Display) GetFilterNum(filterKey string) (interface{}, error) {
37 if _, ok := d.Filter[filterKey]; !ok {
38 return 0, errMissingFilterKey
40 switch val := d.Filter[filterKey].(type) {
41 case int, int16, int32, int64, int8, uint, uint16, uint32, uint64, uint8, float32, float64:
45 return 0, errInvalidFilterType
48 // GetFilterBoolean give the filter keyword return the boolean value
49 func (d *Display) GetFilterBoolean(filterKey string) (bool, error) {
50 if _, ok := d.Filter[filterKey]; !ok {
51 return false, errMissingFilterKey
53 switch val := d.Filter[filterKey].(type) {
57 return false, errInvalidFilterType