Hacker News new | ask | show | jobs
by burntsushi 3064 days ago
Good post! Crossposting my comment from that other crusty news aggregator:

Alternative 1a is to use Alternative 1 with https://github.com/BurntSushi/go-sumtype /plug

go-sumtype requires the interface to be sealed (which you're already doing) and one small annotation:

    //go-sumtype:decl TheInterfaceName
Then you just run `go-sumtype`

    $ go-sumtype $(go list ./... | grep -v vendor)
and it will do exhaustiveness checks in any type switch in which `TheInterfaceName` participates. This will prevent the "For example, during a refactor a handler might be removed but a type that implements the interface is not." failure mode mentioned in the article.