xyproto / permissions2

:closed_lock_with_key: Middleware for keeping track of users, login states and permissions
MIT License
513 stars 38 forks source link

Support for fasthttp #29

Open gaby opened 1 year ago

gaby commented 1 year ago

Hello, are there any plans to add support for fasthttp? https://github.com/valyala/fasthttp https://github.com/valyala/fasthttp#switching-from-nethttp-to-fasthttp

Thanks!

xyproto commented 11 months ago

Thanks for the feature request! Adding support for fasthttp is not on my immediate TODO list, but I like the idea.

If the goal is increased performance, is ie. echo (which supports net/http interfaces) an alternative?

gaby commented 11 months ago

@xyproto I'm one of the maintainers for @GoFiber which is based on fasthttp. Looking at the examples I could try using your library with the net/http to fasthttp adaptor. If I get it to work I will share an example here.

xyproto commented 3 months ago

Using https://github.com/valyala/fasthttp/fasthttpadaptor should work.

I am using it here: https://github.com/xyproto/algernon/blob/main/engine/serve.go

I'll have to try using it together with permissions2 to see if any changes to permissions2 is needed.

gaby commented 3 months ago

@xyproto The problem with adaptor is that it adds overhead. So if you are checking for auth in all your handlers, they will all get slower.

gaby commented 3 months ago

Another thing, your examples folder is part of permissions2. This makes it so that anyone using module has to install a lot of dependencies.

https://github.com/xyproto/permissions2/blob/main/v2/go.mod#L6

So even if i have a fasthttp server, my go.mod will end with gin, chi, martini, negroni, etc which are not needed for permissions2

xyproto commented 3 months ago

I see, I thought the overhead of fasthttpadaptor was minimal, but I have not benchmarked it yet.

What would be the best way to support fasthttp? To add a middleware function, like lu does? https://github.com/vincentLiuxiang/lu

Thanks for pointing out the issue with the examples folder, I am renaming it to cmd.

xyproto commented 3 months ago

I gave you full access to this repository, btw, in case you have a good plan for adding support for fasthttp and want to add it. I would have to look more into fasthttp first.

gaby commented 3 months ago

@xyproto Yes, the best way is to have a native fasthttp middleware.

Adaptor while great it has convert/adapt each net/http to a fasthttp ctx.

An excellent examples for using adaptor: Prometheus Endpoint

gaby commented 3 months ago

I gave you full access to this repository, btw, in case you have a good plan for adding support for fasthttp and want to add it. I would have to look more into fasthttp first.

Will do, thanks 💪

xyproto commented 3 months ago

btw, if fasthttp needs to be imported by permissions2 in order to support fasthttp, that would require all users of permission2 to also get fasthttp as a dependency, right? Is there a way to support fasthttp without having to import it in permissions2?

gaby commented 3 months ago

@xyproto They have instructions here https://github.com/valyala/fasthttp?tab=readme-ov-file#switching-from-nethttp-to-fasthttp

Would have to check what sections of net/http permissions2 is using.

Yes, it would require importing it. I have to think if there's a way around that by creating an interface.

xyproto commented 3 months ago

In worst case, perhaps a separate permissions package for supporting fasthttp would be needed.

gaby commented 3 months ago

I will do a PR tonight to update the CI process first. Will look imto fasthttp after that. 💪