# Interfaces 101 : Parsing Command Flags Ep. 9

- Published: March 27, 2023
- Author: Ardan Labs
- URL: https://www.ardanlabs.com/blog/2023/03/interfaces-101-parsing-command-flags-ep-9.html

### Introduction

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.

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

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.


--- 

### Video

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