# 中间件定义
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()
}
← 可观察性-Prometheus 跨域中间件 →