This guide explains how to implement interceptors in Goa, focusing on the flexibility provided by the interceptor pattern and the next
function.
Implementation Structure
Goa generates type-safe interceptor interfaces based on your design. Each interceptor method follows this signature:
func (i *Interceptor) MethodName(ctx context.Context, info *InterceptorInfo, next goa.Endpoint) (any, error)
Where:
ctx
: The request contextinfo
: Type-safe access to payload and result attributesnext
: The wrapped endpoint (service method or next interceptor)
The Next Function
The next
function is the key to interceptor flexibility. It represents the
wrapped endpoint and can be called at any point in your interceptor code. This
enables three main patterns: