Documentation ¶
Overview ¶
Package httpread provides common un-marshalling operations from HTTP responses.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Csv ¶
Csv reads a http response into a [][]string. The response is checked for its status code and the http.Response.Body is closed.
func JSON ¶
JSON reads a http response into a data container using a json decoder. The response is checked for its status code and the http.Response.Body is closed.
Example ¶
JSON reads marshals the body of a http.Response to a struct.
package main import ( "fmt" "io/ioutil" "net/http" "strings" "github.com/gotohr/fritzctl/httpread" ) func main() { f := func() (*http.Response, error) { return &http.Response{Body: ioutil.NopCloser(strings.NewReader(`{"x": 2, "y": 5}`))}, nil } var pt = struct { X int Y int }{} httpread.JSON(f, &pt) fmt.Println(pt) }
Output: {2 5}
func String ¶
String reads a http response into a string. The response is checked for its status code and the http.Response.Body is closed.
Example ¶
String reads the body of a http.Response to a string.
package main import ( "fmt" "io/ioutil" "net/http" "strings" "github.com/gotohr/fritzctl/httpread" ) func main() { f := func() (*http.Response, error) { return &http.Response{Body: ioutil.NopCloser(strings.NewReader("text"))}, nil } s, _ := httpread.String(f) fmt.Println(s) }
Output: text
func XML ¶
XML reads a http response into a data container using an XML decoder. The response is checked for its status code and the http.Response.Body is closed.
Example ¶
XML reads marshals the body of a http.Response to a struct.
package main import ( "fmt" "io/ioutil" "net/http" "strings" "github.com/gotohr/fritzctl/httpread" ) func main() { f := func() (*http.Response, error) { return &http.Response{Body: ioutil.NopCloser(strings.NewReader(`<point><x>2</x><y>5</y></point>`))}, nil } var pt = struct { X int `xml:"x"` Y int `xml:"y"` }{} httpread.XML(f, &pt) fmt.Println(pt) }
Output: {2 5}
Types ¶
This section is empty.