Monday, April 29, 2024
HomeGolangParsing Command Flags Ep. 9

Parsing Command Flags Ep. 9


Introduction

In episode 8, Miki developed a Go HTTP consumer that had a way to examine the well being of a theoretical API. The strategy would assemble the request URL and return an error based mostly on the response code acquired from the server. Miki then created a kind that might mock Go’s http.RoundTripper interface and exchange his consumer’s transport with mentioned sort to check it. To enhance the efficacy, Miki’s stub will simulate an misguided response to see if his consumer’s Well being technique is working as supposed.

On this video, Miki will write a program that decodes a command line flag representing an deal with right into a Go struct. Previous to writing any code, Miki lays out the method he’ll be taking and the way the flag bundle leverages the Worth interface to decode flags handed from the command line. The following step Miki takes is to create a struct sort that implements the flag.Worth interface. Certainly one of this implementation’s highlights is how Miki makes use of the Set technique to carry out validation on the string handed to make sure the deal with is formatted correctly. Watch and study how one can decode a command flag right into a user-defined struct sort.

Issues you’ll study on this video

  • How you can decode a command flag right into a Go sort.
  • The function of every technique discovered on the flag.Worth interface.
  • How you can validate a user-defined flag worth.

Video



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments