12.8 Returning Concrete Types vs Interfaces: API Design Guidance
Right, let’s settle this. One of the most common, and frankly, most tedious debates in Go API design is whether to return concrete types (*MyStruct) or interfaces (MyInterface). You’ll find zealots on both sides, but the correct answer, as with most things in engineering, is a deeply unsatisfying “it depends.” But I’ll give you the tools to know what it depends on. The core principle is this: Your function’s return type is a contract, a promise. The narrower the promise, the more freedom you have to change your implementation later without breaking the world.