Introduction
In episode 4, Miki outlined an enumerated kind that happy Go’s fmt.Stringer
interface. By implementing the fmt.Stringer
interface, Miki can specify how his enumerators have been printed inside a formatted string and on this case, he anticipated the values to be displayed as a predetermined textual content worth. Miki additionally identified how utilizing the worth of the strategy’s receiver inside the Stringer
methodology may end up in a recursive loop.
On this video, Miki will outline an uncommon operate that returns the variety of traces in a file with the io.Author
interface. Step one he’ll take is to declare a variable and set it to the worth returned by the os
package deal’s Open
operate. Miki does this as a result of the concrete kind of the variable returned satisfies the io.Reader
interface. The following step he takes is to outline a sort that’s an alias of a primitive kind and implement the strategies required for the kind alias to fulfill the io.Author
interface. Watch and discover ways to implement the io.Author
interface and the way it interacts with Go’s io
package deal.
Issues you’ll be taught on this video
- Implement the
io.Author
interface with a sort that’s an alias of a primitive kind. - Go a variable as an interface kind to operate.
- Repurpose the
io.Author
interface to depend traces of code.
Video