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?

Thidasa Pankaja
  • 930
  • 8
  • 25
  • 44

1 Answers1

2

You can set the middleware within the /platform route:

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

r.Route("/webhooks", func(r chi.Router) {
    r.Get("/", ...)
})
blackgreen
  • 34,072
  • 23
  • 111
  • 129