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

Thank You for Subscribing

Check your email for confirmation.

Interfaces 101 : Parsing Command Flags Ep. 9

Author image

Ardan Labs


In episode 8, Miki developed a Go HTTP client that had a method to check the health of a theoretical API. The method would construct the request URL and return an error based on the response code received from the server. Miki then created a type that would mock Go’s http.RoundTripper interface and replace his client’s transport with said type to test it. To improve the efficacy, Miki’s stub will simulate an erroneous response to see if his client’s Health method is working as intended.

In this video, Miki will write a program that decodes a command line flag representing an address into a Go struct. Prior to writing any code, Miki lays out the approach he’ll be taking and how the flag package leverages the Value interface to decode flags passed from the command line. The next step Miki takes is to create a struct type that implements the flag.Value interface. One of this implementation’s highlights is how Miki makes use of the Set method to perform validation on the string passed to ensure the address is formatted properly. Watch and learn how you can decode a command flag into a user-defined struct type.

Things you will learn in this video

  • How to decode a command flag into a Go type.
  • The role of each method found on the flag.Value interface.
  • How to validate a user-defined flag value.


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
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.