1. 程式人生 > >Building a REPL System with Go & Docker

Building a REPL System with Go & Docker

Building a REPL System with Go & Docker

I recently was looking for something to work on, and dug up one of my old projects. During a hackathon, I built a tool for running short scripts interactively online using docker. Eventually, I managed to cobble together a decent-looking system with a basic editor on the left and an interactive terminal on the right. You could quickly switch languages with a drop-down menu and it would automatically switch the language of the environment and load the associated “Hello World.” The save system was not particularly user-friendly and the code was rather inefficient (e.g. shelled out to the docker command), but it was the minimum level required to implement the concept.

After going back to this project, I was able to simplify many inefficient. Instead of rewriting requests to docker commands to be run by GoTTY, I connected directly to docker (through the docker “sdk”) and converted TTY IO into a websocket stream. As a side effect of this, I was able to eliminate the temporary key-value store I built to hold code in-between uploading the code and running it — now I could send it directly through the websocket to docker. On the frontend I originally had to use JS to generate absolute positions due to components not respecting CSS sizing. Now, most of the layout uses CSS. In addition, the old save system which required users to remember an arbitrary number has been replaced with a save button that writes the save identifier into the page URL, so REPLs can be shared by link (

like this).