When I want to learn a new programming language, my typical method of doing this is to either take an existing small project and port it over to the new language, or come up with a small, yet practical problem to solve. I’m kinda like Johnny Five, in that I need input!

Johnny 5

Number 5 is alive!

I’ve been playing with Go for a little bit, but nothing very serious. I’ve also been playing around with Docker and Kubernetes, so I decided to kill two birds with one stone by building an application in Go as well as learning how to package it up in a Docker container.

Introducing Where To Now. It’s designed to vary the webpage that might show up when a user inside a corporation hits “Home” on their default browser. The idea being that “Home” might be a different target depending on the time of day.

When workers fire up their laptops at home in the morning and open their browser, content managers could first send users to an internal COVID-19 status page (or perhaps something from the CDC or WHO). When the local stock markets open, users could be routed to websites that read out stock data. In the afternoon to promote wellness content managers would want the home page to be a “Get up and stretch” message.

All of this is possible to be done in a number of ways, but I wanted to make a simple traffic cop style HTTP Listener in Go that would forward (via a HTTP redirect 303 message) the browser to a desired target depending on the time of day. It’s extremely lightweight as this is not a proxy, just a redirect. With the Docker instance, you can run it from anywhere. Just configure the new default home page to this address, and it will do the hard work for you.

To illustrate, here’s a potential timeline of sites to redirect to:

  • Overnight and to the morning hours (so when someone connects for work), display a COVID-19 Status page.
  • When markets open, Marketwatch.
  • 30 minutes after they open, go to the Corporate Intranet Homepage.
  • At 11:30, go to a food delivery service for lunch ordering.
  • At 2pm, a STAND UP AND STRETCH page.
  • At 4pm, back to the Corporate Intranet Homepage.
  • At 6pm, a reminder to shut down and finish for the day.

There are some limitations to the application. For one, it is not time-zone aware. This feature could be built into the application to attempt to geo-locate based on IP address. Or, if you wanted to make this time-zone capable today, you would just deploy multiple instances and vary the port number (ensuring the configuration is adjusted for the SERVER’S time zone, which could be UTC!). While we do get some details like the User-Agent and Remote IP, we won’t get much more to make additional routing/config decisions on. Potentially something for the future in that a small amount of Javascript could be passed and the results interpreted to do more fun things, but this was more proof of concept and a weekend project.

All in all, the project was completed over the weekend and gave me a good feel for Go and how to package applications in general as a container.

This post originally appeared on BrandenWilliams.com.

Possibly Related Posts: