Introduction
In episode 9, Miki discussed how a command flag can be decoded into a user defined type with the Value
interface. As a recap, the Value
interface consists of two methods: one for serializing the underlying concrete type and one for deserializing a string into an object. To put this interface to the test, Miki wrote a command that had a flag to specify a network address. While implementing the Set
method of the Value
interface, Miki demonstrated how to add validation for your program’s flags.
![](../../../images/blog/interfaces-10.jpg?v=1)
In this video, Miki will build an HTTP server with one endpoint to display the health of his server. The first step he took was to define a HTTP handler to illustrate how a Go handler becomes a HandlerFunc
. Next, Miki will design a function signature for middleware with the goal of abstracting input and output as much as possible. Miki will then define a logging middleware that measures the time of a request. Watch and learn how you can write a HTTP handler that is extendable with middleware.
Things you will learn in this video
- Define a route with Go’s http package.
- The ideal design for a middleware function.
- How to implement an HTTP server with composability in mind.
- Define logging middleware with Go’s STD library.
Video