Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to create a middleware for any type of handlers? #95

Open
remyduthu opened this issue Jan 12, 2022 · 0 comments
Open

Is it possible to create a middleware for any type of handlers? #95

remyduthu opened this issue Jan 12, 2022 · 0 comments

Comments

@remyduthu
Copy link
Contributor

Hi! I'm trying to create a middleware for handlers. I succeeded to create a middleware for a specific type of handler. For example:

func (s *service) myMiddleware(h res.CollectionHandler) res.CollectionHandler {
  return func(r res.CollectionRequest) {
    // Do stuff...
    h(r)
  }
}

s.router.Handle("teams",
  res.GetCollection(s.myMiddleware(s.findTeams)),
  ...
)

I would like to know if I can create a middleware for any type of handler? For example:

s.router.Handle("...",
  res.GetCollection(s.myMiddleware(s.findTeams)),
  res.GetModel(s.myMiddleware(s.findTeam)),
  res.Call(s.myMiddleware(s.createTeam)),
)

I can't find a common "generic" interface to use, is it even possible?

Thanks in advance 🙌

@remyduthu remyduthu changed the title Is it possible to create a middleware for any type of handler? Is it possible to create a middleware for any type of handlers? Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant