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 : Go's Logging Interface Ep. 4

Author image

Ardan Labs

Introduction

In episode 3, Miki implemented a type that satisfied Go’s error interface. The odd thing about his type was it would be considered not-nil although no value was set for it. To get a better understanding of the situation, Miki gives a brief explanation of how Go determines if an error value is nil, and in this case, Miki specified the type of the variable returned to be a pointer of his custom error type which blindsided Go’s mechanism to determine a nil value. Miki chose this example because it demonstrated the importance of declaring an error with its type set as the error interface.

In this video, Miki will focus on Go’s fmt.Stringer interface and how it can be used to control how Go prints your type. The first step he’ll take is to define an enumerated type representing different keys loosely based on the book Ready Player One. Miki will then implement the method required for Go’s fmt.Stringer interface which will specify how his enumerated type will be printed as a string. Watch and learn how to define a function that will decide how your type is formatted and printed.

Things you will learn in this video

  • Define a Go enum with a user-defined type.
  • How to implement Go’s fmt.Stringer interface.
  • Specify how your type is represented with string formatting.

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.