initial commit
This commit is contained in:
commit
e309b478f5
5 changed files with 453 additions and 0 deletions
52
cmd/main.go
Normal file
52
cmd/main.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// 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}}},
|
||||
}
|
||||
|
||||
func main() {
|
||||
f := filter.NewQuery("String:s*").GenericFilter(data)
|
||||
if f != nil {
|
||||
for _, v := range f.(Filter) {
|
||||
fmt.Println("Generic:", v)
|
||||
}
|
||||
}
|
||||
filter.NewQuery("String:s*").Filter(&data)
|
||||
for _, v := range data {
|
||||
fmt.Println("Interface:", v)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue