本文整理汇总了Golang中github.com/opesun/chill/frame/interfaces.Filter类的典型用法代码示例。如果您正苦于以下问题:Golang Filter类的具体用法?Golang Filter怎么用?Golang Filter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RegenerateFulltext
func (c *C) RegenerateFulltext(a iface.Filter) error {
cb := func(doc map[string]interface{}, g iface.Grabbed) error {
upd := c.updateFromDoc(doc)
return g.Update(upd)
}
return a.Iterate(cb)
}
示例2: New
func (c *C) New(a iface.Filter) ([]map[string]interface{}, error) {
scheme, err := c.getScheme(a.Subject(), "Insert")
if err != nil {
return nil, err
}
return convert.SchemeToFields(scheme, nil)
}
示例3: UpdateAll
func (b *Basics) UpdateAll(a iface.Filter, data map[string]interface{}) error {
upd := map[string]interface{}{
"$set": data,
}
_, err := a.UpdateAll(upd)
return err
}
示例4: Insert
func (c *C) Insert(a iface.Filter, data map[string]interface{}) error {
m, err := c.decrypt(data)
if err != nil {
return err
}
m["created"] = time.Now().UnixNano() // Should include user too maybe.
return a.Insert(m)
}
示例5: Update
func (c *C) Update(a iface.Filter, data map[string]interface{}) error {
m, err := c.decrypt(data)
if err != nil {
return err
}
m["modified"] = time.Now().UnixNano()
return a.Update(m)
}
示例6: DeleteFile
func (c *C) DeleteFile(a iface.Filter, data map[string]interface{}) error {
upd := map[string]interface{}{
"$pull": map[string]interface{}{
data["key"].(string): data["file"],
},
}
return a.Update(upd)
}
示例7: SaveFulltext
func (c *C) SaveFulltext(a iface.Filter) error {
doc, err := a.FindOne()
if err != nil {
return err
}
upd := c.updateFromDoc(doc)
return a.Update(upd)
}
示例8: FindUser
// Finds a user by id.
func FindUser(a iface.Filter, id bson.ObjectId) (map[string]interface{}, error) {
q := m{"_id": id}
v, err := a.AddQuery(q).FindOne()
if err != nil {
return nil, err
}
delete(v, "password")
return v, nil
}
示例9: namePass
// Finds he user by name password equality.
func namePass(a iface.Filter, name, encoded_pass string) (map[string]interface{}, error) {
q := bson.M{
"name": name,
"password": encoded_pass,
}
doc, err := a.AddQuery(q).FindOne()
if err != nil {
return nil, err
}
return convert.Clean(doc).(map[string]interface{}), nil
}
示例10: Edit
func (c *C) Edit(a iface.Filter) ([]map[string]interface{}, error) {
doc, err := a.FindOne()
if err != nil {
return nil, err
}
scheme, err := c.getScheme(a.Subject(), "Update")
if err != nil {
return nil, err
}
return convert.SchemeToFields(scheme, doc)
}
示例11: NameAvailable
// Returns true if the username is still available.
func NameAvailable(a iface.Filter, name string) (bool, error) {
q := bson.M{"slug": slugify.S(name)}
users, err := a.AddQuery(q).Find()
if err != nil {
return false, err
}
if len(users) > 0 {
return false, nil
}
return true, nil
}
示例12: RegisterUser
func RegisterUser(a iface.Filter, user map[string]interface{}) (bson.ObjectId, error) {
user["password"] = hashPass(user["password"].(string))
if _, has := user["level"]; !has {
user["level"] = 100
}
user_id := bson.NewObjectId()
user["_id"] = user_id
err := a.Insert(user)
if err != nil {
return "", fmt.Errorf("Name is not unique.")
}
return user_id, nil
}
示例13: Update
func (c *C) Update(a iface.Filter, data map[string]interface{}) error {
files_map, has := data["_files"].(map[string]interface{})
upd := map[string]interface{}{
"$set": data,
}
if has {
ids, err := a.Ids()
if err != nil {
return err
}
err = c.moveFiles(a.Subject(), ids[0].Hex(), files_map)
if err != nil {
return err
}
delete(data, "_files")
upd["$addToSet"] = eachIfNeeded(fileheadersToFilenames(files_map))
}
err := a.Update(upd)
if err != nil {
return err
}
if c.Ev != nil {
c.Ev.Fire("Updated", a)
c.Ev.Fire(a.Subject()+"Updated", a)
}
return nil
}
示例14: Edit
func (c *C) Edit(a iface.Filter) (string, error) {
doc, err := a.FindOne()
if err != nil {
return "", err
}
for _, v := range ignore {
delete(doc, v)
}
marsh, err := json.MarshalIndent(doc, "", "\t")
if err != nil {
return "", err
}
return string(marsh), nil
}
示例15: Update
func (b *Basics) Update(a iface.Filter, data map[string]interface{}) error {
upd := map[string]interface{}{
"$set": data,
}
err := a.Update(upd)
if err != nil {
return err
}
if b.Ev != nil {
b.Ev.Fire("Updated", a)
b.Ev.Fire(a.Subject()+"Updated", a)
}
return nil
}