Updating a dynamic hostname with Go

My last project ended a few weeks ago and I have the opportunity to spend some time on learning new stuff. In recent years I mostly worked within the Java and Kotlin ecosystem, so I figured why not look at something completely new for a change? I decided to have a look at Go and in the past weeks I’ve worked through various online resources. While lessons and examples are certainly necessary to get into something new, I’m learning most when I put things to use. So after some guided learning, I decided to migrate a shell script that I’ve been using to update a dynamic hostname managed by ddnss.de regularly to Go. I need this mainly so that my home server is available via IPv6 (having my FritzBox update the hostname would assign the FritzBox’s IPv6 address to the hostname).

My first Go version was a quite similar to the existing shell script, I feel that it was still a lot easier to understand and less brittle. If since migrated the application to Cobra Commands, a Go library for creating cli applications. Now the application can query and update ddnss managed hostnames and it also provides a few flags for both use cases.

I’ve also added unit tests. After playing around with the default xunit style go facilities, I now migrated those tests to Ginkgo using the Gomega assertion library. While the default facilities are quite easy to use, the tests are more readable and concise using Gingko, I think.

I’m sure there are lots of opportunities for improvement, but I’m happy with the result so far: It’s easier to read and less brittle than my previous script. You can have a look at the code here, and I’m happy to learn about improvements that could be made!

Leave a Reply

Your email address will not be published. Required fields are marked *