2
URLリソースからの読み取り方法次の例では、私はhttps://github.com/Kissaki/rest.go APIを使用しました。以下は、私がURLに文字列を書くために使用する例ですhttp://localhost:8080/cool しかし、私はURLからデータを取得する必要があります。GoのURLリソースからの読み取り
package main
import (
"fmt"
"http"
"github.com/nathankerr/rest.go"
)
type FileString struct {
value string
}
func (t *FileString) Index(w http.ResponseWriter) {
fmt.Fprintf(w, "%v", t.value)
}
func main(){
rest.Resource("cool", &FileString{s:"this is file"})
http.ListenAndServe(":3000", nil)
}
を推測しますが、私はresp.Bodyから内容を読みますか教えてもらえますか? – chinmay
'content:= make([] byte、resp.ContentLength); n、err:= resp.Body.Read(content);そのようなものをチェック(エラー)しますか? ContentLengthが1つのチャンク全体で読み込まれるべきでないならば、私は – bjarneh
と誤解していると思います。大量の '[] byte'チャンクでファイル全体を読むことは、' resp.ContentLength'の理想よりも小さくてもかまいません。つまり、ContentLengthが大きいかどうかを示す必要があります。 – bjarneh