Creating common interfaces in Golang

If your API can have multiple implementations, follow this process:

  1. Try to write a vanilla Go interface that supports all implementations.
    1. Do not use interface{} types — #todo consider generics for this
    2. If your interface uses a custom type, extract it into a separate package.
  2. If you cannot come up with a clean interface, don’t do it. Instead, introduce an educational pattern for everyone to follow, to write alternative implementations.

Do not perform Golang-gymnastics to achieve generic code. Such tricks end up with code that’s hard to follow.

October 30, 2022