What Day Is It Today?

What Day Is It Today?
Photo by Towfiqu barbhuiya / Unsplash

One of the common phrases I've picked up over the years and reach for on a regular basis is "it's today today", often in response to someone asking how I'm doing.

I think it dates back to an IRC user I used to encounter who owned something like, whatdayisittoday.net (which is apparently registered, but down behind Cloudflare) which I found particularly funny at the time, and it's always surprised what sticks with us over the years. See also "The horrors persist, but so do I", and the always appropriate "yes" when given two possibilities.

As I remember it, whatdayisittoday.net at one point in time was simply a text response of "It's today today!". Later on I believe it was replaced with some sort of calendar/dashboard/newsfeed but I'm going to pretend I didn't know that, and rebuild some of my earlier memories of the internet.

Of course I'm going to do it in Go which wasn't around back then, but that's not the important bit.

Why Go?

Simple, I've never done it before.

I've had some experience recently with modifying Go programs to handle changed APIs, but I've never actually sat down and written something net new. Since this is a rather small project it seems like the right candidate to sit down and do so.

All this needs to do is return a simple payload on a couple endpoints, which can't be that hard right?

Getting Ready to Go

There have been a ton of good resources over the years on Go, bookmarked for me to pick up and read starts with the following:

How I write HTTP services in Go after 13 years | Grafana Labs
Mat Ryer, principal engineer at Grafana Labs and host of the Go Time podcast, shares what he’s learned from more than a dozen years of writing HTTP services in Go.

And includes two more resources linked within:

Learn Go with Tests | Learn Go with tests
The files & folders of Go projects with Ben Johnson & Chris James (Go Time #278)
Return guests Ben Johnson & Chris James join Mat & Kris to talk about the files and folders of your Go projects, big and small. Does the holy grail exist, of the perfect structure to rule them all? Or are we doomed to be figuring this out for the rest of our lives?

However I usually find that I learn best by doing, so as a precursor to consuming those resources I'm going to go in completely blind and see where we end up.

Requirements

To consider this a success, we want to:

  • Serve a single page, explaining what day it is today
  • Support an API endpoint, so you can programmatically determine what day it is today
  • The embedded version of the site is nicely displayed wherever embeds are used (Slack, X, etc.)
  • Deploy via Docker

Getting Started

A pretty simple go mod init itstodaytoday.com and we're off to the races.

So far I've found that Go's standard library and included modules cover a pretty good amount of general functionality, which includes things like the net/http module acting as both a client and a server.

Which we can wrap the whole thing up, 2 routes and all in about 25 total lines:

package main

import (
	"fmt"
	"log"
	"net/http"
)

var rootHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "It's today today!")
})

var apiHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	JsonResponse := `{"message": "It's today today!"}`
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprint(w, JsonResponse)
})

func main() {
	http.Handle("/api/today", apiHandler)
	http.Handle("/", rootHandler)

	log.Fatal(http.ListenAndServe(":8080", nil))
}

Job's done, see you next time!

Which we can test and see working as we expect after running the coroutine

The Open Graph Protocol

As the next step in our blind implementation, we can throw some values into the more common Open Graph attributes:

var homepage string = `
<html prefix="og: https://ogp.me/ns#">
	<head>
		<title>It's Today Today!</title>
		<meta property="og:title" content="It's Today Today!" />
		<meta property="og:type" content="website" />
		<meta property="og:url" content="https://itstodaytoday.com" />
		<meta property="og:image" content="/cal.png" />
		<meta property="og:description" content="A website that determines whether the current date is today or not." />
	</head>
	<body>
		<p>It's today today!</p>
	</body>
</html>
`

However there are 2 additional problems - the first, we need to serve an image now if we want to display one. Secondly, we're going to need to jump ahead and do some dockerization/hosting if we want to be able to throw our link into various services and make sure it renders correctly.

Thankfully we can opt to serve an entire directory with only a single line:

http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("./public/"))))

Very similar to defining a route elsewhere

For hosting, we can wrap this up in a docker container with ease:

FROM golang:1.24

WORKDIR /app

COPY ./src .

CMD ["go", "run", "main.go"]

This is the shortest Dockerfile I've written in recent memory, by far

And we can wrap that up further with docker compose:

services:
  its-today-today:
    build: .
    ports:
      - "8080:8080"

This port mapping won't stick around once we're behind a proxy

Which, after adding a line of logging when the server starts, gives us:

Success!

Skipping on some of the GitHub/Container Registry magic since this about Go, we condense things down to a pre-built container and toss it up:

services:
  its-today-today:
    image: tharbakim/itstodaytoday:latest

The shortest docker-compose.yml I've written in years, to pair with our earlier Dockerfile

Sprinkle in some existing reverse proxy magic, and we can finally ask ourselves the question,

What day is it today?

Testing an embed (Discord):

And, using this blog's embed capabilties:

It’s Today Today!
A website that determines whether the current date is today or not.

No image? Looks like we missed something we'll pick up next time.

Conclusion

With that, our original list:

  • Serve a single page, explaining what day it is today
  • Support an API endpoint, so you can programmatically determine what day it is today
  • The embedded version of the site is nicely displayed wherever embeds are used (Slack, X, etc.)
  • Deploy via Docker

Is all completed with our barebones implementation. And, thankfully, the "Deploy via Docker" step should continue to work with minimal changes in the future.

Source code available at: https://github.com/tharbakim/ItsTodayToday

Live demo typically available at: https://itstodaytoday.com

Follow up posts will be added here as they appear.