本文整理汇总了Golang中github.com/rs/rest-layer/resource.Lookup.Filter方法的典型用法代码示例。如果您正苦于以下问题:Golang Lookup.Filter方法的具体用法?Golang Lookup.Filter怎么用?Golang Lookup.Filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/rs/rest-layer/resource.Lookup
的用法示例。
在下文中一共展示了Lookup.Filter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Find
func (m *mockHandler) Find(ctx context.Context, lookup *resource.Lookup, page, perPage int) (*resource.ItemList, error) {
if m.err != nil {
return nil, m.err
}
m.queries = append(m.queries, lookup.Filter())
return &resource.ItemList{len(m.items), page, m.items}, nil
}
示例2: Find
func (m *mockHandler) Find(ctx context.Context, lookup *resource.Lookup, page, perPage int) (*resource.ItemList, error) {
if m.err != nil {
return nil, m.err
}
m.lock.Lock()
defer m.lock.Unlock()
m.queries = append(m.queries, lookup.Filter())
return &resource.ItemList{Total: len(m.items), Page: page, Items: m.items}, nil
}
示例3: Clear
// Clear clears all items from the memory store matching the lookup
func (m *MemoryHandler) Clear(ctx context.Context, lookup *resource.Lookup) (total int, err error) {
m.Lock()
defer m.Unlock()
err = handleWithLatency(m.Latency, ctx, func() error {
ids := make([]interface{}, len(m.ids))
copy(ids, m.ids)
for _, id := range ids {
item, _, err := m.fetch(id)
if err != nil {
return err
}
if !lookup.Filter().Match(item.Payload) {
continue
}
m.delete(item.ID)
total++
}
return nil
})
return total, err
}
示例4: Find
// Find items from memory matching the provided lookup
func (m *MemoryHandler) Find(ctx context.Context, lookup *resource.Lookup, page, perPage int) (list *resource.ItemList, err error) {
m.RLock()
defer m.RUnlock()
err = handleWithLatency(m.Latency, ctx, func() error {
items := []*resource.Item{}
// Apply filter
for _, id := range m.ids {
item, _, err := m.fetch(id)
if err != nil {
return err
}
if !lookup.Filter().Match(item.Payload) {
continue
}
items = append(items, item)
}
// Apply sort
if len(lookup.Sort()) > 0 {
s := sortableItems{lookup.Sort(), items}
sort.Sort(s)
}
// Apply pagination
total := len(items)
start := (page - 1) * perPage
end := total
if perPage > 0 {
end = start + perPage
if start > total-1 {
start = 0
end = 0
} else if end > total-1 {
end = total
}
}
list = &resource.ItemList{total, page, items[start:end]}
return nil
})
return list, err
}
示例5: getQuery
// getQuery transform a resource.Lookup into a Mongo query
func getQuery(l *resource.Lookup) (bson.M, error) {
return translateQuery(l.Filter())
}