DEV Community

Cover image for Decorator Patterns In Go

Decorator Patterns In Go

Kresno Fatih Imani on January 28, 2024

Introduction The decorator pattern is a software design pattern that lets you add more functionality on top of an existing logic. The fi...
Collapse
 
tnypxl profile image
tnypxl

I love the decorator pattern, but I've yet to find a good use case for it in Go. But it's been absolutely clutch in other languages.

Collapse
 
mrkresnofatih profile image
Kresno Fatih Imani

Hi @tnypxl , one use I've done in the past are middlewares that you can stack before/after an API request truly gets processed by your backend logic. e.g. authentication token validation, request body validation, telemetry, ratelimiting, a/b testing enablement, etc.