本文整理汇总了Golang中github.com/dgryski/carbonzipper/carbonzipperpb.GlobResponse.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang GlobResponse.Name方法的具体用法?Golang GlobResponse.Name怎么用?Golang GlobResponse.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dgryski/carbonzipper/carbonzipperpb.GlobResponse
的用法示例。
在下文中一共展示了GlobResponse.Name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: findHandler
func findHandler(w http.ResponseWriter, req *http.Request) {
logger.Debugln("request: ", req.URL.RequestURI())
Metrics.FindRequests.Add(1)
rewrite, _ := url.ParseRequestURI(req.URL.RequestURI())
v := rewrite.Query()
format := req.FormValue("format")
v.Set("format", "protobuf")
rewrite.RawQuery = v.Encode()
query := req.FormValue("query")
var tld string
if i := strings.IndexByte(query, '.'); i > 0 {
tld = query[:i]
}
// lookup tld in our map of where they live to reduce the set of
// servers we bug with our find
Config.mu.RLock()
var backends []string
var ok bool
if backends, ok = Config.metricPaths[tld]; !ok || backends == nil || len(backends) == 0 {
backends = Config.Backends
}
Config.mu.RUnlock()
responses := multiGet(backends, rewrite.RequestURI())
if responses == nil || len(responses) == 0 {
logger.Logln("find: error querying backends for: ", rewrite.RequestURI())
http.Error(w, "find: error querying backends", http.StatusInternalServerError)
return
}
metrics, paths := findHandlerPB(w, req, responses)
// update our cache of which servers have which metrics
Config.mu.Lock()
for k, v := range paths {
Config.metricPaths[k] = v
}
Config.mu.Unlock()
switch format {
case "protobuf":
w.Header().Set("Content-Type", "application/protobuf")
var result pb.GlobResponse
query := req.FormValue("query")
result.Name = &query
result.Matches = metrics
b, _ := proto.Marshal(&result)
w.Write(b)
case "json":
w.Header().Set("Content-Type", "application/json")
jEnc := json.NewEncoder(w)
jEnc.Encode(metrics)
case "", "pickle":
w.Header().Set("Content-Type", "application/pickle")
var result []map[string]interface{}
for _, metric := range metrics {
mm := map[string]interface{}{
"metric_path": *metric.Path,
"isLeaf": *metric.IsLeaf,
}
result = append(result, mm)
}
pEnc := pickle.NewEncoder(w)
pEnc.Encode(result)
}
}