04.2-creating-my-first-Read-Method-with-func-accepting-io.Reader

command
v0.0.0-...-9882766 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

The purpose of this program is to test creating a Read Method who follows the rule for Read methods, by taking a []byte as input, and returning n characters read, and an error telling when done or failed.

We will create a new type called storage, which can hold some data of type string The storage type shall have a read method, to read the content of the storage into a variable. There shall also be a function to create and initialize a new storage (will be done in next version)

Since our new type has a Read method, it will also satisfy the interface io.Reader. We will create another read-something function which takes an io.Reader as input to demonstrate that we can now use myStorage as input where it is asked for io.Reader as input type.

Jump to

Keyboard shortcuts

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