當前位置: 首頁>>代碼示例>>Golang>>正文


Golang HttpResponse.Append方法代碼示例

本文整理匯總了Golang中wharf/util.HttpResponse.Append方法的典型用法代碼示例。如果您正苦於以下問題:Golang HttpResponse.Append方法的具體用法?Golang HttpResponse.Append怎麽用?Golang HttpResponse.Append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wharf/util.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.Append方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ListTaskHandler

/*List the information about one or more tasks.
The information is not in detai */
func ListTaskHandler(w http.ResponseWriter, r *http.Request) {
	//the return value :response
	var response util.HttpResponse
	inputInfo, err := GetInfoFromRequest(&w, r)
	if err != nil {
		return
	}
	var userRequest PsRequest
	userRequest.Init()
	for thisFlag, flagValue := range inputInfo.Data {
		switch thisFlag {
		case "a":
			userRequest.All, _ = strconv.ParseBool(flagValue)
		case "l":
			userRequest.Latest, _ = strconv.ParseBool(flagValue)
		case "n":
			userRequest.Name = flagValue
		case "i":
			userRequest.Image = flagValue
		case "t":
			userRequest.Type = flagValue
		default:
			response.Set(util.INVALID_INPUT, "invalid flag of wharf ps.")
			io.WriteString(w, response.String())
			return
		}
	}
	//flags conflict
	if userRequest.All && userRequest.Latest ||
		userRequest.All && userRequest.Name != "" ||
		userRequest.Latest && userRequest.Name != "" {
		response.Set(util.INVALID_INPUT, "flags are conflicting with each other.")
		io.WriteString(w, response.String())
		return
	}

	var psIterm PsOutput
	//task name is set || latest is set
	if userRequest.Name != "" || userRequest.Latest {
		if userRequest.Latest {
			userRequest.Name = LatestTask
		}
		thisTask, exists := Tasks[userRequest.Name]
		if !exists {
			response.Set(util.INVALID_INPUT, `No such task with name of "`+userRequest.Name+`"`)
			io.WriteString(w, response.String())
			return
		} else {
			fillPSOutpusWithTask(&psIterm, &thisTask)
			data, _ := json.Marshal(psIterm)
			response.Set(util.OK, string(data))
			io.WriteString(w, response.String())
			return
		}
	}
	//traverse all the task in Tasks
	for _, thisTask := range Tasks {
		response.Status = util.OK
		if (userRequest.All == true || thisTask.Status == RUNNING) &&
			(userRequest.Image == "" || thisTask.Cmd.ImageName == userRequest.Image) &&
			(userRequest.Type == "" || thisTask.Cmd.TypeName == userRequest.Type) {
			fillPSOutpusWithTask(&psIterm, &thisTask)
			data, _ := json.Marshal(psIterm)
			response.Append(string(data))
		}
		io.WriteString(w, response.String())
	}
	return
}
開發者ID:qzan9,項目名稱:wharf,代碼行數:71,代碼來源:manager.go


注:本文中的wharf/util.HttpResponse.Append方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。