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 ¶ added in v1.4.18
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 ¶ added in v1.4.16
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/bpicode/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 ¶ added in v1.4.16
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/bpicode/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 ¶ added in v1.4.16
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/bpicode/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.