Go Package io: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 23: Line 23:
=<tt>Writer</tt>=
=<tt>Writer</tt>=
{{External|https://golang.org/pkg/io/#Writer}}
{{External|https://golang.org/pkg/io/#Writer}}
Files opened with <code>[[Go_Package_os#os.Create.28.29|os.Create()]]</code> implement <code>io.Writer</code>.
=<tt>Closer</tt>=
=<tt>Closer</tt>=
{{External|https://golang.org/pkg/io/#Closer}}
{{External|https://golang.org/pkg/io/#Closer}}

Revision as of 00:09, 19 December 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:

Unmarshalling JSON from a Reader into a struct

Files opened with os.Create() implement io.Reader.

Writer

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

Files opened with os.Create() implement io.Writer.

Closer

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

ReadCloser

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