func (i *IndexSet) GetIndex(name string) (Index, error) {
	for _, idx := range i.Indexes {
		if idx.Name == name {
			return idx, nil
		}
	}
	return Index{}, fmt.Errorf("index %s not found", name)
}
GetIndex returns an index by name, or an error if not found.
package resbadger
import (
	"bytes"
	"fmt"
	"github.com/dgraph-io/badger"
	res "github.com/jirenius/go-res"
)
type Index struct {
	Name string
	Key func(interface{}) []byte
}
type IndexSet struct {
	Indexes []Index
	listeners []indexListener
}
type IndexQuery struct {
	Index Index
	KeyPrefix []byte
	FilterKeys func(key []byte) bool
	Offset int
	Limit int
	Reverse bool
}
type indexListener struct {
	cb   func(r res.Resource, before, after interface{})
	name string
}
const ridSeparator = byte(0)
const resultBufSize = 256
const maxInt = int(^uint(0) >> 1)
func (i *IndexSet) Listen(cb func(r res.Resource, before, after interface{})) {
	i.listeners = append(i.listeners, indexListener{cb: cb})
}
func (i *IndexSet) ListenIndex(name string, cb func(r res.Resource, before, after interface{})) {
	i.listeners = append(i.listeners, indexListener{cb: cb, name: name})
}
func (i *IndexSet) triggerListeners(name string, r res.Resource, before, after interface{}) {
	for _, il := range i.listeners {
		if il.name == name {
			il.cb(r, before, after)
		}
	}
}