A Real-World Example of Go Interfaces

How to implement Go interfaces and why they’re awesome

Dirk Hoekstra
Nov 6 · 2 min read
Photo by Sean Lim on Unsplash

Suppose I’m building a web app in Go. In my app, I want to send a message to my users. I can send a message to the users via email or SMS. This would be a perfect use case for interfaces.

For this hypothetical web app, I create the following main.go file.

You've completed your member preview for this month, but when you sign up for a free Medium account, you get one more story.
Already have an account? Sign in

Dirk Hoekstra

Written by

Practical programmer that likes building cool stuff!

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade