gonest
Request Pipeline

Interceptors

AOP-style before/after wrapping around the handler

An Interceptor wraps the Handler AOP-style. Build one with gonest.NewInterceptor(func(interceptor *gonest.Interceptor) {...}).

var TimingInterceptor = gonest.NewInterceptor(func(interceptor *gonest.Interceptor) {
  interceptor.Handler(func(ctx *gonest.RestContext, next gonest.InterceptorNext) {
    // code here runs BEFORE the handler
    next(ctx)
    // code here runs AFTER the handler
  })
})

Interceptors run after Guards and wrap the Handler plus everything nested in it. They're controller-scoped only.

Applying an interceptor

var UserController = gonest.NewController(func(controller *gonest.Controller) {
  controller.Interceptors(TimingInterceptor)
})

Next steps

On this page