当前位置: 首页>>代码示例>>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;未经允许,请勿转载。