Go Package io: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 15: Line 15:
{{External|https://golang.org/pkg/io/#Reader}}
{{External|https://golang.org/pkg/io/#Reader}}
An interface that exposes <code>Read()</code>.
An interface that exposes <code>Read()</code>.
<code>Reader</code>s can be used to unmarshall JSON into structs as shown here: {{JSON_in_Go#With_a_Reader|Unmarshalling JSON from a Reader into a struct}}
=<tt>Writer</tt>=
=<tt>Writer</tt>=
{{External|https://golang.org/pkg/io/#Writer}}
{{External|https://golang.org/pkg/io/#Writer}}
=<tt>ReadCloser</tt>=
=<tt>ReadCloser</tt>=
An interface that exposes basic <code>Read()</code> and <code>Close()</code> methods. The <code>http.Request</code> body is a <code>ReadCloser</code>. See <code>[[#Reader|Reader]]</code>.
An interface that exposes basic <code>Read()</code> and <code>Close()</code> methods. The <code>http.Request</code> body is a <code>ReadCloser</code>. See <code>[[#Reader|Reader]]</code>.

Revision as of 20:00, 16 October 2023

External

Internal

Overview

The io package consists of a few functions, but mostly interfaces used by other packages.

Reader

https://golang.org/pkg/io/#Reader

An interface that exposes Read().

Readers can be used to unmarshall JSON into structs as shown here: Template:JSON in Go

Writer

https://golang.org/pkg/io/#Writer

ReadCloser

An interface that exposes basic Read() and Close() methods. The http.Request body is a ReadCloser. See Reader.