中间件定义

  1. type CustomMiddleware struct {
  2. }
  3. func NewCustomMiddleware() *CustomMiddleware {
  4. return &CustomMiddleware { }
  5. }
  6. func (middleware*CustomMiddleware ) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext)) {
  7. // ....
  8. next(ctx)
  9. }

main.go

  1. func main() {
  2. app.CreateDefaultBuilder(registerEndpointRouterConfig).
  3. Configure(func(app *app.WebApplicationBuilder) {
  4. app.UseMiddleware(NewCustomMiddleware())
  5. }).Build().Run()
  6. }