Injecting dependencies for better Go

Perhaps the biggest habit I see from other languages (primarily JavaScript, Ruby and Python) is an attraction to a little bit of magic when it comes to construction of dependencies. Engineers tend to try and hide away the complexity of the initialisation of their application by putting bits such as connecting to a database within components of their application, rather than doing this within the main function. Here’s an example of that:...

August 16, 2021 · Noah Stride

Go: stop using sql.Open!

One of my biggest gripes in Go relates to the database/sql package. This roots from two concerns, which can be seen in the snippet below: import ( "database/sql" "time" _ "github.com/go-sql-driver/mysql" ) func connect() (*sql.DB, error){ db, err := sql.Open("mysql", "user:[email protected]/database?parseTime=true") if err != nil { return nil, err } return db, nil } Global registration is scary One of the first things in the file is the import statement, where we import the go-sql-driver/mysql package and mark it as unused with an underscore....

March 21, 2021 · Noah Stride

Retaking the Helm: Kubernetes manifests as Go - WIP

This post is still work in progress :) A lot about Helm leaves me extremely dissatisfied, especially as manifests grow more complicated and I aim to reduce duplication. The templating language itself always leaves me thinking that there simply has to be a better way of doing this that doesn’t involve painstakingly adding {{ indent xyz }} and carefully stripping whitespace. It occurred to me that it must be possible to use the Kubernetes API types to directly define or generate these manifests from Go code, thus allowing us to use standard Go loops and conditionals or even including entire pre-written sections with the benefits of type-checking and editor auto-complete when working on more complex manifests....

September 13, 2020 · Noah Stride