io

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TeeReadCloser

func TeeReadCloser(rc io.ReadCloser, w io.Writer) io.ReadCloser

TeeReadCloser returns a ReadCloser that writes to w what it reads from rc. All reads from rc performed through it are matched with corresponding writes to w. There is no internal buffering - the write must complete before the read completes. Any error encountered while writing is reported as a read error.

func Handler(rw http.ResponseWriter, req *http.Request) {
	buf := bytes.NewBuffer(make([]byte, 0, req.ContentLength))
	body := io.TeeReadCloser(req.Body, buf)

	var payload interface{}
	if err := json.NewDecoder(body).Decode(&payload); err != nil {
		log.Printf("invalid json: %q", buf.String())
	}
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL