Módulo 15 · Design Patterns in Go — Lección 5 de 8 · ~6 min
Decorator / Middleware
Wrap behavior around something you can't change
Decorator wraps an object in another that shares its interface and adds behavior — logging, timing, auth — without touching the wrapped thing. You already met the Go form of this in module 06: HTTP middleware. A middleware takes a handler and returns a handler.
The signature is the whole pattern: func(next http.Handler) http.Handler. The wrapper does its extra work, then calls next.ServeHTTP to delegate. Because the return type matches the input type, decorators stack — Logging(Auth(handler)) is a handler that logs, then authorizes, then runs the real one.