本文整理汇总了Golang中github.com/evergreen-ci/evergreen/plugin.WriteJSON函数的典型用法代码示例。如果您正苦于以下问题:Golang WriteJSON函数的具体用法?Golang WriteJSON怎么用?Golang WriteJSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WriteJSON函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:tychoish,项目名称:evergreen,代码行数:27,代码来源:task.go
示例2: IncKeyHandler
// IncKeyHandler increments the value stored in the given key, and returns it
func IncKeyHandler(w http.ResponseWriter, r *http.Request) {
key := ""
err := util.ReadJSONInto(r.Body, &key)
if err != nil {
evergreen.Logger.Logf(slogger.ERROR, "Error geting key: %v", err)
plugin.WriteJSON(w, http.StatusInternalServerError, err.Error())
return
}
change := mgo.Change{
Update: bson.M{
"$inc": bson.M{"value": 1},
},
ReturnNew: true,
Upsert: true,
}
keyVal := &KeyVal{}
_, err = db.FindAndModify(KeyValCollection, bson.M{"_id": key}, nil, change, keyVal)
if err != nil {
evergreen.Logger.Logf(slogger.ERROR, "error doing findAndModify: %v", err)
plugin.WriteJSON(w, http.StatusInternalServerError, err.Error())
return
}
plugin.WriteJSON(w, http.StatusOK, keyVal)
}
开发者ID:3rf,项目名称:keyval,代码行数:28,代码来源:keyval.go
示例3: getNote
// getNote retrieves the latest note from the database.
func (bbp *BuildBaronPlugin) getNote(w http.ResponseWriter, r *http.Request) {
taskId := mux.Vars(r)["task_id"]
n, err := NoteForTask(taskId)
if err != nil {
plugin.WriteJSON(w, http.StatusInternalServerError, err.Error())
return
}
if n == nil {
plugin.WriteJSON(w, http.StatusOK, "")
return
}
plugin.WriteJSON(w, http.StatusOK, n)
}
开发者ID:IanWhalen,项目名称:build-baron-plugin,代码行数:14,代码来源:build_baron.go
示例4: insertTask
// insertTask creates a TaskJSON document with the data sent in the request body.
func insertTask(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"]
rawData := map[string]interface{}{}
err := util.ReadJSONInto(r.Body, &rawData)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBlob := TaskJSON{
TaskId: t.Id,
TaskName: t.DisplayName,
Name: name,
BuildId: t.BuildId,
Variant: t.BuildVariant,
ProjectId: t.Project,
VersionId: t.Version,
CreateTime: t.CreateTime,
Revision: t.Revision,
RevisionOrderNumber: t.RevisionOrderNumber,
Data: rawData,
IsPatch: t.Requester == evergreen.PatchVersionRequester,
}
_, err = db.Upsert(collection, bson.M{TaskIdKey: t.Id, NameKey: name}, jsonBlob)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, "ok")
return
}
开发者ID:tychoish,项目名称:evergreen,代码行数:36,代码来源:task.go
示例5: AttachFilesHandler
// AttachFilesHandler updates file mappings for a task or build
func AttachFilesHandler(w http.ResponseWriter, r *http.Request) {
task := plugin.GetTask(r)
evergreen.Logger.Logf(slogger.INFO, "Attaching files to task %v", task.Id)
fileEntry := &artifact.Entry{}
fileEntry.TaskId = task.Id
fileEntry.TaskDisplayName = task.DisplayName
fileEntry.BuildId = task.BuildId
err := util.ReadJSONInto(r.Body, &fileEntry.Files)
if err != nil {
message := fmt.Sprintf("error reading file definitions: %v", err)
evergreen.Logger.Errorf(slogger.ERROR, message)
http.Error(w, message, http.StatusBadRequest)
return
}
if err := fileEntry.Upsert(); err != nil {
message := fmt.Sprintf("Error updating artifact file info: %v", err)
evergreen.Logger.Errorf(slogger.ERROR, message)
http.Error(w, message, http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, fmt.Sprintf("Artifact files for task %v successfully attached", task.Id))
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:27,代码来源:files_command.go
示例6: 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)
}
开发者ID:sr527,项目名称:evg-json,代码行数:61,代码来源:version.go
示例7: AttachResultsHandler
//XXX remove this once the transition is complete...
//AttachResultsHandler is an API hook for receiving and updating test results
func AttachResultsHandler(w http.ResponseWriter, r *http.Request) {
task := plugin.GetTask(r)
if task == nil {
message := "Cannot find task for attach results request"
evergreen.Logger.Errorf(slogger.ERROR, message)
http.Error(w, message, http.StatusBadRequest)
return
}
results := &model.TestResults{}
err := util.ReadJSONInto(r.Body, results)
if err != nil {
message := fmt.Sprintf("error reading test results: %v", err)
evergreen.Logger.Errorf(slogger.ERROR, message)
http.Error(w, message, http.StatusBadRequest)
return
}
// set test result of task
if err := task.SetResults(results.Results); err != nil {
message := fmt.Sprintf("Error calling set results on task %v: %v", task.Id, err)
evergreen.Logger.Errorf(slogger.ERROR, message)
http.Error(w, message, http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, "Test results successfully attached")
}
开发者ID:markbenvenuto,项目名称:evergreen,代码行数:27,代码来源:attach_plugin.go
示例8: GetManifest
func (m *ManifestPlugin) GetManifest(w http.ResponseWriter, r *http.Request) {
project := mux.Vars(r)["project_id"]
revision := mux.Vars(r)["revision"]
version, err := version.FindOne(version.ByProjectIdAndRevision(project, revision))
if err != nil {
http.Error(w, fmt.Sprintf("error getting version for project %v with revision %v: %v",
project, revision, err), http.StatusBadRequest)
return
}
if version == nil {
http.Error(w, fmt.Sprintf("version not found for project %v, with revision %v", project, revision),
http.StatusNotFound)
return
}
foundManifest, err := manifest.FindOne(manifest.ById(version.Id))
if err != nil {
http.Error(w, fmt.Sprintf("error getting manifest with version id %v: %v",
version.Id, err), http.StatusBadRequest)
return
}
if foundManifest == nil {
http.Error(w, fmt.Sprintf("manifest not found for version %v", version.Id), http.StatusNotFound)
return
}
plugin.WriteJSON(w, http.StatusOK, foundManifest)
return
}
开发者ID:tychoish,项目名称:evergreen,代码行数:30,代码来源:manifest_plugin.go
示例9: 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)
}
开发者ID:tychoish,项目名称:evergreen,代码行数:58,代码来源:history.go
示例10: 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)
}
开发者ID:tychoish,项目名称:evergreen,代码行数:44,代码来源:task.go
示例11: handleTaskTag
// handleTaskTags will update the TaskJSON's tags depending on the request.
func handleTaskTag(w http.ResponseWriter, r *http.Request) {
t, err := task.FindOne(task.ById(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{VersionIdKey: t.Version, NameKey: mux.Vars(r)["name"]},
bson.M{"$unset": bson.M{TagKey: 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{VersionIdKey: t.Version, NameKey: mux.Vars(r)["name"]},
bson.M{"$set": bson.M{TagKey: inTag.Tag}})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, "")
}
开发者ID:sr527,项目名称:evg-json,代码行数:43,代码来源:tag.go
示例12: FetchVarsHandler
// FetchVarsHandler is an API hook for returning the project variables
// associated with a task's project.
func FetchVarsHandler(w http.ResponseWriter, r *http.Request) {
task := plugin.GetTask(r)
if task == nil {
http.Error(w, "task not found", http.StatusNotFound)
return
}
projectVars, err := model.FindOneProjectVars(task.Project)
if err != nil {
message := fmt.Sprintf("Failed to fetch vars for task %v: %v", task.Id, err)
evergreen.Logger.Logf(slogger.ERROR, message)
http.Error(w, message, http.StatusInternalServerError)
return
}
if projectVars == nil {
plugin.WriteJSON(w, http.StatusOK, ExpansionVars{})
return
}
plugin.WriteJSON(w, http.StatusOK, projectVars.Vars)
return
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:23,代码来源:fetch_command.go
示例13: getTasksForVersion
// getTasksForVersion sends back the list of TaskJSON documents associated with a version id.
func getTasksForVersion(w http.ResponseWriter, r *http.Request) {
jsonForTasks, err := findTasksForVersion(mux.Vars(r)["version_id"], mux.Vars(r)["name"])
if jsonForTasks == nil {
http.Error(w, "{}", http.StatusNotFound)
return
}
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
plugin.WriteJSON(w, http.StatusOK, jsonForTasks)
return
}
开发者ID:sr527,项目名称:evg-json,代码行数:14,代码来源:version.go
示例14: 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)
}
开发者ID:sr527,项目名称:evg-json,代码行数:24,代码来源:tag.go
示例15: 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)
}
开发者ID:tychoish,项目名称:evergreen,代码行数:15,代码来源:task.go
示例16: 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)
}
开发者ID:tychoish,项目名称:evergreen,代码行数:24,代码来源:commit.go
示例17: buildFailuresSearch
// BuildFailuresSearchHandler handles the requests of searching jira in the build
// failures project
func (bbp *BuildBaronPlugin) buildFailuresSearch(w http.ResponseWriter, r *http.Request) {
taskId := mux.Vars(r)["task_id"]
task, err := model.FindTask(taskId)
if err != nil {
plugin.WriteJSON(w, http.StatusInternalServerError, err.Error())
return
}
jql := taskToJQL(task)
jiraHandler := thirdparty.NewJiraHandler(
bbp.opts.Host,
bbp.opts.Username,
bbp.opts.Password,
)
results, err := jiraHandler.JQLSearch(jql)
if err != nil {
message := fmt.Sprintf("%v: %v, %v", JIRAFailure, err, jql)
evergreen.Logger.Errorf(slogger.ERROR, message)
plugin.WriteJSON(w, http.StatusInternalServerError, message)
return
}
plugin.WriteJSON(w, http.StatusOK, results)
}
开发者ID:IanWhalen,项目名称:build-baron-plugin,代码行数:26,代码来源:build_baron.go
示例18: servePatch
// servePatch is the API hook for returning patch data as json
func servePatch(w http.ResponseWriter, r *http.Request) {
task := plugin.GetTask(r)
patch, err := task.FetchPatch()
if err != nil {
msg := fmt.Sprintf("error fetching patch for task %v from db: %v", task.Id, err)
evergreen.Logger.Logf(slogger.ERROR, msg)
http.Error(w, msg, http.StatusInternalServerError)
return
}
if patch == nil {
msg := fmt.Sprintf("no patch found for task %v", task.Id)
evergreen.Logger.Errorf(slogger.ERROR, msg)
http.Error(w, msg, http.StatusNotFound)
return
}
plugin.WriteJSON(w, http.StatusOK, patch)
}
开发者ID:tessavitabile,项目名称:evergreen,代码行数:18,代码来源:git_apply_patch.go
示例19: MockPluginEcho
func MockPluginEcho(w http.ResponseWriter, request *http.Request) {
arg1 := mux.Vars(request)["param1"]
arg2, err := strconv.Atoi(mux.Vars(request)["param2"])
if err != nil {
http.Error(w, "bad val for param2", http.StatusBadRequest)
return
}
newTask := plugin.GetTask(request)
if newTask != nil {
//task should have been populated for us, by the API server
plugin.WriteJSON(w, http.StatusOK, map[string]string{
"echo": fmt.Sprintf("%v/%v/%v", arg1, arg2, newTask.Id),
})
return
}
http.Error(w, "couldn't get task from context", http.StatusInternalServerError)
}
开发者ID:sr527,项目名称:evergreen,代码行数:18,代码来源:plugin_test.go
示例20: getTags
// getTags finds TaskJSONs that have tags
func getTags(w http.ResponseWriter, r *http.Request) {
t, err := task.FindOne(task.ById(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{ProjectIdKey: t.Project, TagKey: bson.M{"$exists": true, "$ne": ""}}},
{"$project": bson.M{TagKey: 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)
}
开发者ID:sr527,项目名称:evg-json,代码行数:20,代码来源:tag.go
注:本文中的github.com/evergreen-ci/evergreen/plugin.WriteJSON函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论