# Interfaces 101 : Determine LOC with io.Writer Ep. 5

- Published: February 27, 2023
- Author: Ardan Labs
- URL: https://www.ardanlabs.com/blog/2023/02/interfaces-101-determine-loc-with-iowriter.html

### Introduction

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.

![](../../../images/blog/interfaces-05.jpg?v=1)

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

- Implement the `io.Writer` interface with a type that’s an alias of a primitive type.
- Pass a variable as an interface type to function.
- Repurpose the `io.Writer` interface to count lines of code.

--- 

### Video

<div class="post-video-container">
	<iframe
	    width="640"
	    height="480"
	    src="https://www.youtube.com/embed/72TYNqi5VdM"
	    frameborder="0"
	    allow="autoplay; encrypted-media"
	    allowfullscreen
	>
	</iframe>
</div>
