Subscribe to the Ardan Labs Insider

You’ll get our FREE Video Series & special offers on upcoming training events along with notifications on our latest blog posts.

Included in your subscription
  • Access to our free video previews
  • Updates on our latest blog posts
  • Discounts on upcoming events

Valid email required.

Submit failed. Try again or message us directly at hello@ardanlabs.com.

Thank You for Subscribing

Check your email for confirmation.

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

Author image

Ardan Labs

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.

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

Go Training

We have taught Go to thousands of developers all around the world since 2014. There is no other company that has been doing it longer and our material has proven to help jump start developers 6 to 12 months ahead of their knowledge of Go. We know what knowledge developers need in order to be productive and efficient when writing software in Go.

Our classes are perfect for both experienced and beginning engineers. We start every class from the beginning and get very detailed about the internals, mechanics, specification, guidelines, best practices and design philosophies. We cover a lot about "if performance matters" with a focus on mechanical sympathy, data oriented design, decoupling and writing production software.

Capital One
Cisco
Visa
Teradata
Red Ventures

Interested in Ultimate Go Corporate Training and special pricing?

Let’s Talk Corporate Training!

Join Our Online
Education Program

Our courses have been designed from training over 30,000 engineers since 2013, and they go beyond just being a language course. Our goal is to challenge every student to think about what they are doing and why.