本文整理汇总了Golang中github.com/rs/rest-layer/resource.Lookup类的典型用法代码示例。如果您正苦于以下问题:Golang Lookup类的具体用法?Golang Lookup怎么用?Golang Lookup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Lookup类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:apuigsech,项目名称:rest-layer,代码行数:7,代码来源:routing_test.go
示例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
}
开发者ID:rs,项目名称:rest-layer,代码行数:9,代码来源:routing_test.go
示例3: OnFind
// OnFind implements resource.FindEventHandler interface
func (a AuthResourceHook) OnFind(ctx context.Context, lookup *resource.Lookup, page, perPage int) error {
// Reject unauthorized users
user, found := UserFromContext(ctx)
if !found {
return resource.ErrUnauthorized
}
// Add a lookup condition to restrict to result on objects owned by this user
lookup.AddQuery(schema.Query{
schema.Equal{Field: a.UserField, Value: user.ID},
})
return nil
}
开发者ID:rs,项目名称:rest-layer,代码行数:13,代码来源:main.go
示例4: getSort
// getSort transform a resource.Lookup into a Mongo sort list.
// If the sort list is empty, fallback to _id.
func getSort(l *resource.Lookup) []string {
ln := len(l.Sort())
if ln == 0 {
return []string{"_id"}
}
s := make([]string, ln)
for i, sort := range l.Sort() {
if len(sort) > 0 && sort[0] == '-' {
s[i] = "-" + getField(sort[1:])
} else {
s[i] = getField(sort)
}
}
return s
}
开发者ID:rs,项目名称:rest-layer-mongo,代码行数:17,代码来源:lookup.go
示例5: 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
}
开发者ID:rs,项目名称:rest-layer-mem,代码行数:22,代码来源:mem.go
示例6: 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
}
开发者ID:rs,项目名称:rest-layer-mem,代码行数:40,代码来源:mem.go
示例7: getQuery
// getQuery transform a resource.Lookup into a Mongo query
func getQuery(l *resource.Lookup) (bson.M, error) {
return translateQuery(l.Filter())
}
开发者ID:rs,项目名称:rest-layer-mongo,代码行数:4,代码来源:lookup.go
注:本文中的github.com/rs/rest-layer/resource.Lookup类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论