Mingobingo!

2024-06-15
software

mingobingo is a very simple demonstration of how one can build a Go program that carries static HTML (and JS/CSS/...) assets inside its binary version, as well as serve an API request *and* provides a websocket interface to serve more data.

If you're impatient, you can go and check out the project on GitHub already.

"But why?", you might ask?

Because I'm playing with the idea of a Go tool that, even though it's primarily terminal based, could benefit from a web interface as well. In order to do that, the program would have to expose its data to a local web browser while it is running. And to make it look nice, and react to user actions, it could benefit from styling, Javascript based interactions, use of modern libraries, ... and the data - obviously - could be available to said web client via some APIs. In addition, some of that data is generated sometimes slowly and in batches, so notifying the client about more data is useful.

This led me to to explore what is available out there to package all this into one program. I also wanted to keep it as simple as possible, so that others can take it as a starting point if they wanted to.

We know that Go has a simple built-in HTTP server, that part is easy. As it turns out, it is also capable of embedding files, or even a whole directory of stuff (a "filesystem") into the compiled binary. This is really cool if your users are happy just taking one file (binary) and running with it, without the need for installers, dependencies, deployment paths and the like.

Explanation

There's really not much to it, the simplest thing is to read the source (Go and HTML/Javascript).

The only dependency is on https://github.com/gorilla/websocket which I find acceptable!

There's one optional feature: you can decide to send some data to the websocket interface before it starts responnding. To use this, uncomment the bit in the Go and HTML source as well. I guess more options (e.g. parameters on the API call) could be added at the cost of not being minimalistic any more.

How it looks

Here's a screenshot:

screenshot
Easy!


© Kistel