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


Golang Request.Data方法代碼示例

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


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

示例1: serveShardMapping

// serveShardMapping maps the requested shard and streams data back to the client.
func (h *Handler) serveShardMapping(w http.ResponseWriter, r *http.Request) {
	w.Header().Add("content-type", "application/json")
	var err error

	// Pull out shard ID, query statement, and chunking size.
	q := r.URL.Query()
	pretty := q.Get("pretty") == "true"
	id, s, cs := q.Get("shard"), q.Get("q"), q.Get("chunksize")

	var chunkSize int
	if id == "" {
		httpError(w, `no shard ID specified`, pretty, http.StatusBadRequest)
		return
	}
	shardID, err := strconv.Atoi(id)
	if err != nil {
		httpError(w, `shard ID is not valid`, pretty, http.StatusBadRequest)
		return
	}
	if s == "" {
		httpError(w, `no query specified`, pretty, http.StatusBadRequest)
		return
	}
	if cs == "" {
		chunkSize = 0
	} else {
		chunkSize, err = strconv.Atoi(cs)
		if err != nil {
			httpError(w, `chunk size is not valid`, pretty, http.StatusBadRequest)
			return
		}
	}

	mapper, err := h.TSDBStore.CreateMapper(uint64(shardID), s, chunkSize)
	if err != nil {
		httpError(w, fmt.Sprintf("mapper create: %s", err), pretty, http.StatusInternalServerError)
	}
	if mapper == nil {
		b := MarshalJSON(&tsdb.MapperResponse{}, pretty)
		w.Write(b)
		w.(http.Flusher).Flush()
		return
	}

	if err := mapper.Open(); err != nil {
		httpError(w, fmt.Sprintf("mapper open: %s", err), pretty, http.StatusInternalServerError)
	}
	defer mapper.Close()

	var tagSetsSent bool
	for {
		var r tsdb.MapperResponse

		if !tagSetsSent {
			r.TagSets = mapper.TagSets()
			tagSetsSent = true
		}

		chunk, err := mapper.NextChunk()
		if err != nil {
			httpError(w, fmt.Sprintf("next chunk: %s", err), pretty, http.StatusInternalServerError)
			return
		}
		if chunk != nil {
			data := MarshalJSON(&chunk, pretty)
			r.Data = data
		}

		b := MarshalJSON(&r, pretty)
		w.Write(b)
		w.(http.Flusher).Flush()

		if chunk == nil {
			return
		}
	}
}
開發者ID:rnubel,項目名稱:influxdb,代碼行數:78,代碼來源:handler.go


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