本文整理匯總了Golang中github.com/evergreen-ci/evergreen/db.FindAllQ函數的典型用法代碼示例。如果您正苦於以下問題:Golang FindAllQ函數的具體用法?Golang FindAllQ怎麽用?Golang FindAllQ使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了FindAllQ函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getTaskHistory
func getTaskHistory(t *task.Task, w http.ResponseWriter, r *http.Request) {
var t2 *task.Task = t
var err error
if t.Requester == evergreen.PatchVersionRequester {
t2, err = t.FindTaskOnBaseCommit()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
t.RevisionOrderNumber = t2.RevisionOrderNumber
}
before := []TaskJSON{}
jsonQuery := db.Query(bson.M{
ProjectIdKey: t.Project,
VariantKey: t.BuildVariant,
RevisionOrderNumberKey: bson.M{"$lte": t.RevisionOrderNumber},
TaskNameKey: t.DisplayName,
IsPatchKey: false,
NameKey: mux.Vars(r)["name"]})
jsonQuery = jsonQuery.Sort([]string{"-order"}).Limit(100)
err = db.FindAllQ(collection, jsonQuery, &before)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//reverse order of "before" because we had to sort it backwards to apply the limit correctly:
for i, j := 0, len(before)-1; i < j; i, j = i+1, j-1 {
before[i], before[j] = before[j], before[i]
}
after := []TaskJSON{}
jsonAfterQuery := db.Query(bson.M{
ProjectIdKey: t.Project,
VariantKey: t.BuildVariant,
RevisionOrderNumberKey: bson.M{"$gt": t.RevisionOrderNumber},
TaskNameKey: t.DisplayName,
IsPatchKey: false,
NameKey: mux.Vars(r)["name"]}).Sort([]string{"order"}).Limit(100)
err = db.FindAllQ(collection, jsonAfterQuery, &after)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//concatenate before + after
before = append(before, after...)
// if our task was a patch, replace the base commit's info in the history with the patch
if t.Requester == evergreen.PatchVersionRequester {
before, err = fixPatchInHistory(t.Id, t2, before)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
plugin.WriteJSON(w, http.StatusOK, before)
}
示例2: Find
// Find runs a patch query, returning all patches that satisfy the query.
func Find(query db.Q) ([]Patch, error) {
patches := []Patch{}
err := db.FindAllQ(Collection, query, &patches)
if err == mgo.ErrNotFound {
return nil, nil
}
return patches, err
}
示例3: Find
// Find returns all tasks that satisfy the query.
func Find(query db.Q) ([]Task, error) {
tasks := []Task{}
err := db.FindAllQ(Collection, query, &tasks)
if err == mgo.ErrNotFound {
return nil, nil
}
return tasks, err
}
示例4: Find
func Find(query db.Q) ([]Version, error) {
versions := []Version{}
err := db.FindAllQ(Collection, query, &versions)
if err == mgo.ErrNotFound {
return nil, nil
}
return versions, err
}
示例5: Find
// Find returns all builds that satisfy the query.
func Find(query db.Q) ([]Build, error) {
builds := []Build{}
err := db.FindAllQ(Collection, query, &builds)
if err == mgo.ErrNotFound {
return nil, nil
}
return builds, err
}
示例6: findTasksForVersion
// findTasksForVersion sends back the list of TaskJSON documents associated with a version id.
func findTasksForVersion(versionId, name string) ([]TaskJSON, error) {
var jsonForTasks []TaskJSON
err := db.FindAllQ(collection, db.Query(bson.M{VersionIdKey: versionId,
NameKey: name}), &jsonForTasks)
if err != nil {
if err != mgo.ErrNotFound {
return nil, err
}
return nil, err
}
return jsonForTasks, err
}
示例7: getTaskByTag
// getTaskByTag returns a TaskJSON with a specific task name and tag
func getTaskByTag(w http.ResponseWriter, r *http.Request) {
t := plugin.GetTask(r)
if t == nil {
http.Error(w, "task not found", http.StatusNotFound)
return
}
tagged := []TaskJSON{}
jsonQuery := db.Query(bson.M{
ProjectIdKey: t.Project,
VariantKey: t.BuildVariant,
TaskNameKey: mux.Vars(r)["task_name"],
TagKey: bson.M{"$exists": true, "$ne": ""},
NameKey: mux.Vars(r)["name"]})
err := db.FindAllQ(collection, jsonQuery, &tagged)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, tagged)
}
示例8: FindAll
// FindAll gets every Entry for the given query
func FindAll(query db.Q) ([]Entry, error) {
entries := []Entry{}
err := db.FindAllQ(Collection, query, &entries)
return entries, err
}
示例9: FindTasks
func FindTasks(query db.Q) ([]Task, error) {
tasks := []Task{}
err := db.FindAllQ(TasksCollection, query, &tasks)
return tasks, err
}
示例10: Find
func Find(query db.Q) ([]Event, error) {
events := []Event{}
err := db.FindAllQ(Collection, query, &events)
return events, err
}
示例11: GetAPIHandler
// GetRoutes returns an API route for serving patch data.
func (jsp *JSONPlugin) GetAPIHandler() http.Handler {
r := mux.NewRouter()
r.HandleFunc("/tags/{task_name}/{name}", func(w http.ResponseWriter, r *http.Request) {
t := plugin.GetTask(r)
if t == nil {
http.Error(w, "task not found", http.StatusNotFound)
return
}
tagged := []TaskJSON{}
jsonQuery := db.Query(bson.M{
"project_id": t.Project,
"variant": t.BuildVariant,
"task_name": mux.Vars(r)["task_name"],
"tag": bson.M{"$exists": true, "$ne": ""},
"name": mux.Vars(r)["name"]})
err := db.FindAllQ(collection, jsonQuery, &tagged)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, tagged)
})
r.HandleFunc("/history/{task_name}/{name}", func(w http.ResponseWriter, r *http.Request) {
t := plugin.GetTask(r)
if t == nil {
http.Error(w, "task not found", http.StatusNotFound)
return
}
before := []TaskJSON{}
jsonQuery := db.Query(bson.M{
"project_id": t.Project,
"variant": t.BuildVariant,
"order": bson.M{"$lte": t.RevisionOrderNumber},
"task_name": mux.Vars(r)["task_name"],
"is_patch": false,
"name": mux.Vars(r)["name"]}).Sort([]string{"-order"}).Limit(100)
err := db.FindAllQ(collection, jsonQuery, &before)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//reverse order of "before" because we had to sort it backwards to apply the limit correctly:
for i, j := 0, len(before)-1; i < j; i, j = i+1, j-1 {
before[i], before[j] = before[j], before[i]
}
after := []TaskJSON{}
jsonAfterQuery := db.Query(bson.M{
"project_id": t.Project,
"variant": t.BuildVariant,
"order": bson.M{"$gt": t.RevisionOrderNumber},
"task_name": mux.Vars(r)["task_name"],
"is_patch": false,
"name": mux.Vars(r)["name"]}).Sort([]string{"order"}).Limit(100)
err = db.FindAllQ(collection, jsonAfterQuery, &after)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//concatenate before + after
before = append(before, after...)
plugin.WriteJSON(w, http.StatusOK, before)
})
r.HandleFunc("/data/{name}", func(w http.ResponseWriter, r *http.Request) {
task := plugin.GetTask(r)
if task == nil {
http.Error(w, "task not found", http.StatusNotFound)
return
}
name := mux.Vars(r)["name"]
rawData := map[string]interface{}{}
err := util.ReadJSONInto(r.Body, &rawData)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBlob := TaskJSON{
TaskId: task.Id,
TaskName: task.DisplayName,
Name: name,
BuildId: task.BuildId,
Variant: task.BuildVariant,
ProjectId: task.Project,
VersionId: task.Version,
Revision: task.Revision,
RevisionOrderNumber: task.RevisionOrderNumber,
Data: rawData,
IsPatch: task.Requester == evergreen.PatchVersionRequester,
}
_, err = db.Upsert(collection, bson.M{"task_id": task.Id, "name": name}, jsonBlob)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, "ok")
return
})
//.........這裏部分代碼省略.........
示例12: GetUIHandler
//.........這裏部分代碼省略.........
_, err = db.UpdateAll(collection,
bson.M{"version_id": t.Version, "name": mux.Vars(r)["name"]},
bson.M{"$set": bson.M{"tag": inTag.Tag}})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, "")
})
r.HandleFunc("/tag/{project_id}/{tag}/{variant}/{task_name}/{name}", func(w http.ResponseWriter, r *http.Request) {
var jsonForTask TaskJSON
err := db.FindOneQ(collection,
db.Query(bson.M{"project_id": mux.Vars(r)["project_id"],
"tag": mux.Vars(r)["tag"],
"variant": mux.Vars(r)["variant"],
"task_name": mux.Vars(r)["task_name"],
"name": mux.Vars(r)["name"],
}), &jsonForTask)
if err != nil {
if err != mgo.ErrNotFound {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, "{}", http.StatusNotFound)
return
}
plugin.WriteJSON(w, http.StatusOK, jsonForTask)
})
r.HandleFunc("/commit/{project_id}/{revision}/{variant}/{task_name}/{name}", func(w http.ResponseWriter, r *http.Request) {
var jsonForTask TaskJSON
err := db.FindOneQ(collection,
db.Query(bson.M{"project_id": mux.Vars(r)["project_id"],
"revision": bson.RegEx{"^" + regexp.QuoteMeta(mux.Vars(r)["revision"]), "i"},
"variant": mux.Vars(r)["variant"],
"task_name": mux.Vars(r)["task_name"],
"name": mux.Vars(r)["name"],
"is_patch": false,
}), &jsonForTask)
if err != nil {
if err != mgo.ErrNotFound {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, "{}", http.StatusNotFound)
return
}
plugin.WriteJSON(w, http.StatusOK, jsonForTask)
})
r.HandleFunc("/history/{task_id}/{name}", func(w http.ResponseWriter, r *http.Request) {
t, err := model.FindTask(mux.Vars(r)["task_id"])
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if t == nil {
http.Error(w, "{}", http.StatusNotFound)
return
}
before := []TaskJSON{}
jsonQuery := db.Query(bson.M{
"project_id": t.Project,
"variant": t.BuildVariant,
"order": bson.M{"$lte": t.RevisionOrderNumber},
"task_name": t.DisplayName,
"is_patch": false,
"name": mux.Vars(r)["name"]})
jsonQuery = jsonQuery.Sort([]string{"-order"}).Limit(100)
err = db.FindAllQ(collection, jsonQuery, &before)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//reverse order of "before" because we had to sort it backwards to apply the limit correctly:
for i, j := 0, len(before)-1; i < j; i, j = i+1, j-1 {
before[i], before[j] = before[j], before[i]
}
after := []TaskJSON{}
jsonAfterQuery := db.Query(bson.M{
"project_id": t.Project,
"variant": t.BuildVariant,
"order": bson.M{"$gt": t.RevisionOrderNumber},
"task_name": t.DisplayName,
"is_patch": false,
"name": mux.Vars(r)["name"]}).Sort([]string{"order"}).Limit(100)
err = db.FindAllQ(collection, jsonAfterQuery, &after)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//concatenate before + after
before = append(before, after...)
plugin.WriteJSON(w, http.StatusOK, before)
})
return r
}