1

I've been using go-chi for a project and using an auth middleware for routes like this

r := chi.NewRouter()
r.Use(authService.AuthMiddleware)

r.Route("/platform", func(r chi.Router) {
    r.Get("/version", RequestPlatformVersion)
})

This is applying to all the routes defined after this declaration which are fine. But now I need to add a route that is used for webhooks. I don't want to apply this middleware to that route since it'll fail. How can I do that?

4

1 回答 1

1

您可以在/platform路由中设置中间件:

r.Route("/platform", func(r chi.Router) {
    r.Use(authService.AuthMiddleware)
    r.Get("/version", RequestPlatformVersion)
})

r.Route("/webhooks", func(r chi.Router) {
    r.Get("/", ...)
})
于 2021-12-27T09:27:21.307 回答