Decoupling Storage
To build maintainable microservices, separate your business logic from your data access code.
The Interface:
go type UserRepository interface { GetByID(id int) (*User, error) Save(u *User) error }
By coding to an interface, you can start with an In-Memory implementation and switch to PostgreSQL later without changing your handlers.