Skip to content

自定义中间件

YoyoFx edited this page Dec 8, 2020 · 2 revisions

中间件定义

type CustomMiddleware struct {
}

func NewCustomMiddleware() *CustomMiddleware {
	return &CustomMiddleware { }
}

func (middleware*CustomMiddleware ) Inovke(ctx *context.HttpContext, next func(ctx *context.HttpContext)) {
        // ....
	next(ctx)
}

main.go

func main() {
	app.CreateDefaultBuilder(registerEndpointRouterConfig).
		Configure(func(app *app.WebApplicationBuilder) {
			app.UseMiddleware(NewCustomMiddleware())
		}).Build().Run()
}