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…
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…
cobra: unable to redefine ‘h’ shorthand
“Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files” I’m currently using Cobra in the MediaWiki CLI project and recently came across an error while trying to auto-generate docs. I’m not actually trying to redefine this flag, but it looks like by…
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…