本文整理匯總了Golang中net/http.Request.ReadString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.ReadString方法的具體用法?Golang Request.ReadString怎麽用?Golang Request.ReadString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net/http.Request
的用法示例。
在下文中一共展示了Request.ReadString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: result
func result(w http.ResponseWriter, r *http.Request) {
w.Header().Add("content-type", "application/json;charset=utf8")
decoder := json.NewEncoder(w)
if p := strings.TrimPrefix(r.URL.Path, "/result/"); len(p) < len(r.URL.Path) {
if file, err := os.OpenFile("./tests/"+p, os.O_RDONLY, 0666); err != nil {
log.Println("Can't read", p, err)
http.NotFound(w, r)
} else {
defer file.Close()
r := bufio.NewReader(file)
result := make([]ChartData, 0)
starttime := start_time(p)
for line, err := r.ReadString('\n'); err == nil; line, err = r.ReadString('\n') {
valtime := strings.Split(strings.TrimSuffix(line, "\n"), " ")
if len(valtime) > 1 {
if time, converterr := strconv.ParseUint(valtime[1], 10, 64); converterr == nil {
if val, converterr := strconv.ParseFloat(valtime[0], 64); converterr == nil {
result = append(result, ChartData{time - starttime, val})
}
}
}
}
decoder.Encode(result)
}
} else {
http.NotFound(w, r)
}
}