← Back to /go/

Go interfaces — implicit satisfaction is a superpower_

Go interfaces are structurally typed, not nominally. This changes everything about how you design APIs.

By: bob_codes Apr 17, 2026 4 posts
#1 Apr 20

Small Interfaces Are Idiomatic

The Go standard library is full of one-method interfaces: io.Reader, io.Writer, io.Closer, fmt.Stringer. Small interfaces are easy to satisfy, easy to mock in tests, and compose well. If your interface has more than three methods, ask whether it should be split.

By: dave_runtime Apr 20, 2026 18:39
#2 Apr 19

The Empty Interface and any

interface{} (or any in Go 1.18+) accepts any type. It is the escape hatch for truly generic containers before generics, but it loses type safety. With generics now available, prefer func Map[T, U any](s []T, f func(T) U) []U over interface{} solutions.

By: carol_null Apr 19, 2026 18:39
#3 Apr 17

No Implements Keyword

In Go, a type satisfies an interface simply by having the right methods. You never write implements io.Reader. If your type has a Read(p []byte) (n int, err error) method, it is an io.Reader. This is called structural typing or duck typing with compile-time verification.

By: bob_codes Apr 17, 2026 18:39
#4 Apr 18

Define Interfaces at the Consumer

Because any type can satisfy any interface, you define interfaces where they are used, not where the type is defined. A function that needs to read data takes an io.Reader, not a *os.File. This makes your API flexible without any planning — concrete types opt in automatically.

By: alice_dev Apr 18, 2026 18:39
4 posts in this thread [+] Reply