当前位置: 首页>>代码示例>>Golang>>正文


Golang Iter.All方法代码示例

本文整理汇总了Golang中labix/org/v2/mgo.Iter.All方法的典型用法代码示例。如果您正苦于以下问题:Golang Iter.All方法的具体用法?Golang Iter.All怎么用?Golang Iter.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在labix/org/v2/mgo.Iter的用法示例。


在下文中一共展示了Iter.All方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getCommand

// getCommand takes an actionid and a commandid and returns a command
func getCommand(respWriter http.ResponseWriter, request *http.Request) {
	var err error
	opid := mig.GenID()
	resource := cljs.New(request.URL.String())
	defer func() {
		if e := recover(); e != nil {
			ctx.Channels.Log <- mig.Log{OpID: opid, Desc: fmt.Sprintf("%v", e)}.Err()
			resource.SetError(cljs.Error{Code: fmt.Sprintf("%d", opid), Message: fmt.Sprintf("%v", e)})
			respond(500, resource, respWriter, request, opid)
		}
		ctx.Channels.Log <- mig.Log{OpID: opid, Desc: "leaving getCommand()"}.Debug()
	}()
	var actionID, commandID int
	aid := request.URL.Query()["actionid"][0]
	if aid != "" {
		actionID, err = strconv.Atoi(aid)
		if err != nil {
			panic(err)
		}
	}
	cmdid := request.URL.Query()["commandid"][0]
	if cmdid != "" {
		commandID, err = strconv.Atoi(cmdid)
		if err != nil {
			panic(err)
		}
	}

	// retrieve the action
	cmds := []mig.Command{}
	var iter *mgo.Iter
	if commandID > 0 {
		if actionID > 0 {
			iter = ctx.DB.Col.Cmd.Find(bson.M{"id": commandID, "action.id": actionID}).Iter()
		} else {
			iter = ctx.DB.Col.Cmd.Find(bson.M{"id": commandID}).Iter()
		}
	} else {
		// nothing to search for, return empty resource
		respond(200, resource, respWriter, request, opid)
	}
	err = iter.All(&cmds)
	if err != nil {
		panic(err)
	}
	if len(cmds) == 0 {
		resource.SetError(cljs.Error{Code: fmt.Sprintf("%d", opid), Message: "No command found"})
		respond(404, resource, respWriter, request, opid)
	}
	// store the results in the resource
	for _, cmd := range cmds {
		commandItem, err := commandToItem(cmd)
		if err != nil {
			panic(err)
		}
		resource.AddItem(commandItem)
	}
	respond(200, resource, respWriter, request, opid)
}
开发者ID:joshuarhode,项目名称:mig,代码行数:60,代码来源:api.go

示例2: findPositiveResults

// get an action ID and returns a list of commands that have positive results
func findPositiveResults(actionID int) (cmds []mig.Command, err error) {
	// retrieve the commands that have positive results
	cmds = []mig.Command{}
	var iter *mgo.Iter
	iter = ctx.DB.Col.Cmd.Find(bson.M{"action.id": actionID, "results.0.foundanything": true}).Iter()
	err = iter.All(&cmds)
	return
}
开发者ID:joshuarhode,项目名称:mig,代码行数:9,代码来源:searches.go

示例3: routeKeywords

/*
  GET /k/
  GET /k/:name
  GET /k/:name/r

  Show a page of all the keyword tags, and then the images
  If /k/:name/r then show a random image by keyword name
  Otherwise 404
*/
func routeKeywords(w http.ResponseWriter, r *http.Request) {
	uriChunks := chunkURI(r.URL.Path)
	if r.Method != "GET" ||
		len(uriChunks) > 3 ||
		(len(uriChunks) == 3 && uriChunks[2] != "r") {
		httplog.LogRequest(r, 404)
		http.NotFound(w, r)
		return
	} else if len(uriChunks) == 1 || (len(uriChunks) == 2 && len(uriChunks[1]) == 0) {
		// Path: /k/
		// show a tag cloud!
		kc, err := du.GetKeywords()
		if err != nil {
			serverErr(w, r, err)
			return
		}
		err = ListTagCloudPage(w, kc)
		if err != nil {
			serverErr(w, r, err)
		}
		return
	}

	log.Printf("K: %s (%d)", uriChunks, len(uriChunks))

	var iter *mgo.Iter
	if uriChunks[len(uriChunks)-1] == "r" {
		// Path: /k/
		// TODO determine how to show a random image by keyword ...
		log.Println("random isn't built yet")
		httplog.LogRequest(r, 404)
		return
	} else if len(uriChunks) == 2 {
		// Path: /k/:name
		log.Println(uriChunks[1])
		iter = gfs.Find(bson.M{"metadata.keywords": uriChunks[1]}).Sort("-metadata.timestamp").Limit(defaultPageLimit).Iter()
	}

	files := []types.File{}
	err := iter.All(&files)
	if err != nil {
		serverErr(w, r, err)
		return
	}
	log.Printf("collected %d files", len(files))
	err = ListFilesPage(w, files)
	if err != nil {
		log.Printf("error: %s", err)
	}

	httplog.LogRequest(r, 200)
}
开发者ID:jbowes,项目名称:imgsrv,代码行数:61,代码来源:server.go

示例4: Articles

// Articles given a categoryID and count returns a list of articles.
// Count of 0 means all
func (d *DB) Articles(categoryID uint16, count int, user *User) ([]*Article, error) {
	results := []*Article{}
	query := bson.M{"categoryid": categoryID}

	var iter *mgo.Iter
	switch count {
	case 0:
		iter = d.Items.Find(query).Iter()
	default:
		iter = d.Items.Find(bson.M{"categoryid": categoryID}).Limit(count).Iter()
	}
	err := iter.All(&results)
	return results, err
}
开发者ID:pkar,项目名称:pavlos,代码行数:16,代码来源:models.go

示例5: GetCategories

// GetCategories gets a list of all currently loaded
// categories.
func (d *DB) GetCategories() ([]*Category, error) {
	results := []*Category{}
	var iter *mgo.Iter = d.Categories.Find(nil).Iter()
	err := iter.All(&results)
	return results, err
}
开发者ID:pkar,项目名称:pavlos,代码行数:8,代码来源:models.go

示例6: Triples

// Triples
func (m *Mongo) Triples(graph, sub, pred string, obj interface{}, options *Options) []*Triple {
	g, ok := m.Graphs[graph]
	if !ok {
		log.Error("missing graph ", graph)
		return nil
	}
	sessionCopy := m.Session.Copy()
	defer sessionCopy.Close()
	col := sessionCopy.DB(m.DBName).C(g.ColName)

	var query bson.M
	if options != nil {
		query = m.BuildQuery(graph, sub, pred, obj, options.TripleOverrides)
	} else {
		query = m.BuildQuery(graph, sub, pred, obj, nil)
	}
	// Note that skip only makes sense in the case of sorted results, so if
	// no orderby is given a default subject is used.
	var iter *mgo.Iter
	switch {
	default:
		// no options
		iter = col.Find(query).Iter()
	case options == nil:
		// no options
		iter = col.Find(query).Iter()
	case options.Limit == 0 && options.Offset == 0 && options.OrderBy == "":
		// no options
		iter = col.Find(query).Iter()
	case options.Limit != 0 && options.Offset != 0 && options.OrderBy != "":
		// limit,  orderby
		iter = col.Find(query).Limit(int(options.Limit)).Skip(int(options.Offset)).Sort(options.OrderBy).Iter()
	case options.Limit != 0 && options.Offset != 0 && options.OrderBy == "":
		// limit, skip
		iter = col.Find(query).Limit(int(options.Limit)).Skip(int(options.Offset)).Sort("s").Iter()
	case options.Limit != 0 && options.Offset == 0 && options.OrderBy != "":
		// limit, orderby
		iter = col.Find(query).Limit(int(options.Limit)).Sort(options.OrderBy).Iter()
	case options.Limit != 0 && options.Offset == 0 && options.OrderBy == "":
		// limit
		iter = col.Find(query).Limit(int(options.Limit)).Iter()
	case options.Limit == 0 && options.Offset != 0 && options.OrderBy != "":
		// skip, orderby
		iter = col.Find(query).Skip(int(options.Offset)).Sort(options.OrderBy).Iter()
	case options.Limit == 0 && options.Offset != 0 && options.OrderBy == "":
		// skip
		iter = col.Find(query).Skip(int(options.Offset)).Sort("s").Iter()
	case options.Limit == 0 && options.Offset == 0 && options.OrderBy != "":
		// orderby
		iter = col.Find(query).Sort(options.OrderBy).Iter()
	}

	tripleDocs := []*TripleDoc{}
	err := iter.All(&tripleDocs)
	if err != nil {
		log.Error(err)
		return nil
	}
	results := []*Triple{}
	for _, res := range tripleDocs {
		results = append(results, &Triple{res.Sub, res.Pred, res.Obj})
	}

	return results
}
开发者ID:pkar,项目名称:pfftdb,代码行数:66,代码来源:mongo.go


注:本文中的labix/org/v2/mgo.Iter.All方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。