Reading from USB COM port in go
If you want an easy copy and paste, no nonsense way to print the output of a COM PORT to the terminal in go, then have a look at the code at the bottom of this post. Firstly, the go.bug.st/serial/enumerator package provides a very nice interface for getting details of connected devices, and includes more…
Scanning for iBeacon advertisements in Go
I spent some time this evening faffing around trying to make a Raspberry Pi turn into a device that could detect nearby iBeacons, filtered by signal strength to find the closest, to basically create a kind of iBeacon scanner that spat out the UUID, minor and major values. Eventually, I gave up on the Raspberry…
Autoreload go code on code change
For developers, the ability to autoreload code upon any changes is nothing short of a game-changer. It not only streamlines the development process but also fosters an environment of continuous improvement and experimentation. There are so many packages for languages such as JavaScript for such a behaviour, but I struggled to easily find a simple-to-use…
Automatic cobra command registration with fx
Cobra is a popular Go package for creating CLIs. It provides a lot of functionality for creating commands, subcommands, and flags. However, it can be tedious to manually register all of your commands. fx is a Go package that provides a dependency injection framework. It can be used to automatically register your application components, including…
A copy-paste go SQL mock for GORM
When it comes to writing robust and reliable tests for your Go applications, having a well-structured and efficient testing setup is crucial. One common challenge in testing Go applications is dealing with database interactions. To ensure that your code functions correctly, it’s essential to create a controlled environment for database operations during testing. In this…
Dependency injection in go using fx, and replacing services for test
I’m writing a new go application and ended up giving fx (by uber) a try for dependency injection. The getting started docs were brilliant for my use case (creating an API), but the examples for how to inject mock services for tests were lacking, so I decided to write some code examples of how I…
mwcli CI in Wikimedia GitLab (docker in docker)
mwcli is a golang CLI tool that I have been working on over the past year to replace the mediawiki-docker-dev development environment that I accidently created a few years back (among other things). I didn’t start the CLI, but I did this mediawiki-docker-dev like functionality. As some point through the development journey it became clear…
dockerit v0.0.5 (Easier than docker run)
dockerit is a small CLI tool that I have been working on during the start of 2021. It’s intended to make running one off commands and CLI tooling easier in docker. Rather than having to write a long string of parameters for docker run, instead you can just use dockerit. This applies to both CLI…
Go Docker SDK, Raw Terminal Ctrl+C handling
I spent my weekend in working on a new project called dockerit. It’s a simple wrapper around Docker written in Go and making use of the Docker SDK. One of the biggest sticking points for me, being fairly new with the Golang world, was trying to pass stdin stdout and stderr between the container and…
Simple Go defer code example
In Go, a defer statement will execute a function call just before the function it is called from returns. I found that most of the examples of a Go defer call online seemed to do complicated things with numbers. So here is a nice simple example with just text output. Example You can run this…