本文整理匯總了Golang中github.com/evergreen-ci/evergreen/db.FindOneQ函數的典型用法代碼示例。如果您正苦於以下問題:Golang FindOneQ函數的具體用法?Golang FindOneQ怎麽用?Golang FindOneQ使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了FindOneQ函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getTaskByName
// getTask finds a json document by using thex task that is in the plugin.
func getTaskByName(w http.ResponseWriter, r *http.Request) {
t := plugin.GetTask(r)
if t == nil {
http.Error(w, "task not found", http.StatusNotFound)
return
}
name := mux.Vars(r)["name"]
taskName := mux.Vars(r)["task_name"]
var jsonForTask TaskJSON
err := db.FindOneQ(collection, db.Query(bson.M{VersionIdKey: t.Version, BuildIdKey: t.BuildId, NameKey: name,
TaskNameKey: taskName}), &jsonForTask)
if err != nil {
if err == mgo.ErrNotFound {
plugin.WriteJSON(w, http.StatusNotFound, nil)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if len(r.FormValue("full")) != 0 { // if specified, include the json data's container as well
plugin.WriteJSON(w, http.StatusOK, jsonForTask)
return
}
plugin.WriteJSON(w, http.StatusOK, jsonForTask.Data)
}
示例2: getTasksForLatestVersion
// getTasksForLatestVersion sends back the TaskJSON data associated with the latest version.
func getTasksForLatestVersion(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
var jsonTask TaskJSON
projects := []string{}
err := util.ReadJSONInto(r.Body, &projects)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
versionData := []VersionData{}
for _, project := range projects {
err := db.FindOneQ(collection, db.Query(bson.M{NameKey: name,
ProjectIdKey: project}).Sort([]string{"-" + RevisionOrderNumberKey}).WithFields(VersionIdKey), &jsonTask)
if err != nil {
if err != mgo.ErrNotFound {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, "{}", http.StatusNotFound)
return
}
if jsonTask.VersionId == "" {
http.Error(w, "{}", http.StatusNotFound)
}
jsonTasks, err := findTasksForVersion(jsonTask.VersionId, name)
if jsonTasks == nil {
http.Error(w, "{}", http.StatusNotFound)
return
}
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// get the version commit info
v, err := version.FindOne(version.ById(jsonTask.VersionId))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if v == nil {
http.Error(w, "{}", http.StatusNotFound)
return
}
commitInfo := CommitInfo{
Author: v.Author,
Message: v.Message,
CreateTime: v.CreateTime,
Revision: v.Revision,
VersionId: jsonTask.VersionId,
}
versionData = append(versionData, VersionData{jsonTasks, commitInfo})
}
plugin.WriteJSON(w, http.StatusOK, versionData)
}
示例3: fixPatchInHistory
func fixPatchInHistory(taskId string, base *task.Task, history []TaskJSON) ([]TaskJSON, error) {
var jsonForTask *TaskJSON
err := db.FindOneQ(collection, db.Query(bson.M{"task_id": taskId}), &jsonForTask)
if err != nil {
return nil, err
}
if base != nil {
jsonForTask.RevisionOrderNumber = base.RevisionOrderNumber
}
if jsonForTask == nil {
return history, nil
}
found := false
for i, item := range history {
if item.Revision == base.Revision {
history[i] = *jsonForTask
found = true
}
}
// if found is false, it means we don't have json on the base commit, so it was
// not replaced and we must add it explicitly
if !found {
history = append(history, *jsonForTask)
}
return history, nil
}
示例4: FindOne
// FindOne gets one Host for the given query.
func FindOne(query db.Q) (*Host, error) {
host := &Host{}
err := db.FindOneQ(Collection, query, host)
if err == mgo.ErrNotFound {
return nil, nil
}
return host, err
}
示例5: FindOne
// FindOne returns one build that satisfies the query.
func FindOne(query db.Q) (*Build, error) {
build := &Build{}
err := db.FindOneQ(Collection, query, build)
if err == mgo.ErrNotFound {
return nil, nil
}
return build, err
}
示例6: FindOne
// FindOne runs a patch query, returning one patch.
func FindOne(query db.Q) (*Patch, error) {
patch := &Patch{}
err := db.FindOneQ(Collection, query, patch)
if err == mgo.ErrNotFound {
return nil, nil
}
return patch, err
}
示例7: FindOneOld
// FindOneOld returns one task from the old tasks collection that satisfies the query.
func FindOneOld(query db.Q) (*Task, error) {
task := &Task{}
err := db.FindOneQ(OldCollection, query, task)
if err == mgo.ErrNotFound {
return nil, nil
}
return task, err
}
示例8: FindOne
// FindOne gets one AlertRecord for the given query.
func FindOne(query db.Q) (*AlertRecord, error) {
alertRec := &AlertRecord{}
err := db.FindOneQ(Collection, query, alertRec)
if err == mgo.ErrNotFound {
return nil, nil
}
return alertRec, err
}
示例9: FindOne
func FindOne(query db.Q) (*Version, error) {
version := &Version{}
err := db.FindOneQ(Collection, query, version)
if err == mgo.ErrNotFound {
return nil, nil
}
return version, err
}
示例10: NoteForTask
// NoteForTask returns the note for the given task Id, if it exists.
func NoteForTask(taskId string) (*Note, error) {
n := &Note{}
err := db.FindOneQ(
NotesCollection,
db.Query(bson.D{{TaskIdKey, taskId}}),
n,
)
if err == mgo.ErrNotFound {
return nil, nil
}
return n, err
}
示例11: getTaskById
// getTaskById sends back a JSONTask with the corresponding task id.
func getTaskById(w http.ResponseWriter, r *http.Request) {
var jsonForTask TaskJSON
err := db.FindOneQ(collection, db.Query(bson.M{TaskIdKey: mux.Vars(r)["task_id"], NameKey: 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)
}
示例12: getTaskForVariant
// getTaskForVariant finds a task by name and variant and finds
// the document in the json collection associated with that task's id.
func getTaskForVariant(w http.ResponseWriter, r *http.Request) {
t := plugin.GetTask(r)
if t == nil {
http.Error(w, "task not found", http.StatusNotFound)
return
}
name := mux.Vars(r)["name"]
taskName := mux.Vars(r)["task_name"]
variantId := mux.Vars(r)["variant"]
// Find the task for the other variant, if it exists
ts, err := task.Find(db.Query(bson.M{task.VersionKey: t.Version, task.BuildVariantKey: variantId,
task.DisplayNameKey: taskName}).Limit(1))
if err != nil {
if err == mgo.ErrNotFound {
plugin.WriteJSON(w, http.StatusNotFound, nil)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if len(ts) == 0 {
plugin.WriteJSON(w, http.StatusNotFound, nil)
return
}
otherVariantTask := ts[0]
var jsonForTask TaskJSON
err = db.FindOneQ(collection, db.Query(bson.M{TaskIdKey: otherVariantTask.Id, NameKey: name}), &jsonForTask)
if err != nil {
if err == mgo.ErrNotFound {
plugin.WriteJSON(w, http.StatusNotFound, nil)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if len(r.FormValue("full")) != 0 { // if specified, include the json data's container as well
plugin.WriteJSON(w, http.StatusOK, jsonForTask)
return
}
plugin.WriteJSON(w, http.StatusOK, jsonForTask.Data)
}
示例13: getTaskJSONByTag
// getTaskJSONByTag finds a TaskJSON by a tag
func getTaskJSONByTag(w http.ResponseWriter, r *http.Request) {
var jsonForTask TaskJSON
err := db.FindOneQ(collection,
db.Query(bson.M{"project_id": mux.Vars(r)["project_id"],
TagKey: mux.Vars(r)["tag"],
VariantKey: mux.Vars(r)["variant"],
TaskNameKey: mux.Vars(r)["task_name"],
NameKey: 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
}
if len(r.FormValue("full")) != 0 { // if specified, include the json data's container as well
plugin.WriteJSON(w, http.StatusOK, jsonForTask)
return
}
plugin.WriteJSON(w, http.StatusOK, jsonForTask)
}
示例14: getCommit
func getCommit(w http.ResponseWriter, r *http.Request) {
var jsonForTask TaskJSON
err := db.FindOneQ(collection,
db.Query(bson.M{ProjectIdKey: mux.Vars(r)["project_id"],
RevisionKey: bson.RegEx{"^" + regexp.QuoteMeta(mux.Vars(r)["revision"]), "i"},
VariantKey: mux.Vars(r)["variant"],
TaskNameKey: mux.Vars(r)["task_name"],
NameKey: mux.Vars(r)["name"],
IsPatchKey: false,
}), &jsonForTask)
if err != nil {
if err != mgo.ErrNotFound {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, "{}", http.StatusNotFound)
return
}
if len(r.FormValue("full")) != 0 { // if specified, include the json data's container as well
plugin.WriteJSON(w, http.StatusOK, jsonForTask)
return
}
plugin.WriteJSON(w, http.StatusOK, jsonForTask)
}
示例15: GetUIHandler
func (hwp *JSONPlugin) GetUIHandler() http.Handler {
r := mux.NewRouter()
r.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
plugin.WriteJSON(w, http.StatusOK, "1")
})
r.HandleFunc("/task/{task_id}/{name}/", func(w http.ResponseWriter, r *http.Request) {
var jsonForTask TaskJSON
err := db.FindOneQ(collection, db.Query(bson.M{"task_id": mux.Vars(r)["task_id"], "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("/task/{task_id}/{name}/tags", 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
}
tags := []struct {
Tag string `bson:"_id" json:"tag"`
}{}
err = db.Aggregate(collection, []bson.M{
{"$match": bson.M{"project_id": t.Project, "tag": bson.M{"$exists": true, "$ne": ""}}},
{"$project": bson.M{"tag": 1}}, bson.M{"$group": bson.M{"_id": "$tag"}},
}, &tags)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, tags)
})
r.HandleFunc("/task/{task_id}/{name}/tag", 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
}
if r.Method == "DELETE" {
if _, err = db.UpdateAll(collection,
bson.M{"version_id": t.Version, "name": mux.Vars(r)["name"]},
bson.M{"$unset": bson.M{"tag": 1}}); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, "")
}
inTag := struct {
Tag string `json:"tag"`
}{}
err = util.ReadJSONInto(r.Body, &inTag)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if len(inTag.Tag) == 0 {
http.Error(w, "tag must not be blank", http.StatusBadRequest)
return
}
_, 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) {
//.........這裏部分代碼省略.........