Structural data typing in Go

A common annoyance when doing certain types of API coding is Go’s lack of structural data typing. In my personal experience, this can result in having to write a massive amount of boilerplate to convert between concrete types that are broadly the same, but are either slightly different (say, a DB type that has a few extra fields than a domain type which in turn has a few extra fields than an API return type) or are just in different packages.

Anonymous Interface Intersections in Go

Interface intersections are a quite handy feature in Typescript. For those without Typescript experience, they allow you to easily define a new type that is the intersection of two different types. To pull an example from the language guide, say you have an interface for objects with a colour and an interface for circles, like so: interface Colourful { colour: string; } interface Circle { radius: number; } Now a lot of your logic may deal with only a Colourful object or only a Circle, but sometimes you want to write something that operates only on a circle that is also colourful.