In episode 4, Miki defined an enumerated type that satisfied Go’s fmt.Stringer interface. By implementing the fmt.Stringer interface, Miki can specify how his enumerators were printed within a formatted string and in this case, he expected the values to be displayed as a predetermined text value. Miki also pointed out how using the value of the method’s receiver within the Stringer method can result in a recursive loop.
In this video, Miki will define an unusual function that returns the number of lines in a file with the io.Writer interface. The first step he’ll take is to declare a variable and set it to the value returned by the os package’s Open function. Miki does this because the concrete type of the variable returned satisfies the io.Reader interface. The next step he takes is to define a type that is an alias of a primitive type and implement the methods required for the type alias to satisfy the io.Writer interface. Watch and learn how to implement the io.Writer interface and how it interacts with Go’s io package.
Things you will learn in this video
From the Ardan Community
Get your team up to date with best practices & customized curriculum.
We help you evaluate your architecture, design, structure, tech-debt and human capital.
Learn at your own pace!
Special offers on upcoming training events & our latest blog posts.
Valid email required.
Submit failed. Try again or message us directly at email@example.com.
Check your email for confirmation.
We've built our reputation as educators and bring that mentality to every project. When you partner with us, your team will learn best practices and grow along the way.
Years in Business
Please fill out the form below, and we'll get back to you soon.
Check your email for confirmation of your sent message. We'll get back to you shortly.
Ardan Labs Copyrights © 2023