// Copyright (C) 2017 Marius Schellenberger package main import ( "fmt" "git.giftfish.de/ston1th/filter" ) // Example data structure type Example struct { String string Int int Bool bool Struct Struct1 } type Struct1 struct { String string Struct Struct2 } type Struct2 struct { Int int } // Filter implements the filter.Filter interface type Filter []Example func (v Filter) Len() int { return len(v) } func (v Filter) Index(i int) interface{} { return v[i] } func (v *Filter) Remove(i, j int) { *v = append((*v)[:i], (*v)[j:]...) } // Example data var data = Filter{ {"str1", 42, true, Struct1{"s1", Struct2{1}}}, {"2str", 42, true, Struct1{"s2", Struct2{2}}}, {"str3", 42, false, Struct1{"s3", Struct2{3}}}, {":", 42, false, Struct1{"s3", Struct2{3}}}, } func main() { f, _ := filter.NewQuery("String:s*", filter.AND) d := f.GenericFilter(data) if d != nil { for _, v := range d.(Filter) { fmt.Println("Generic:", v) } } f, _ = filter.NewQuery("Struct.Struct.Int:1 Struct.Struct.Int:2 String::", filter.OR) f.Filter(&data) for _, v := range data { fmt.Println("Interface:", v) } }