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

Support for fasthttp #29

Open
gaby opened this issue Aug 14, 2023 · 13 comments
Open

Support for fasthttp #29

gaby opened this issue Aug 14, 2023 · 13 comments

Comments

@gaby
Copy link
Collaborator

gaby commented Aug 14, 2023

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
Copy link
Owner

xyproto commented Dec 13, 2023

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
Copy link
Collaborator Author

gaby commented Dec 13, 2023

@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
Copy link
Owner

xyproto commented Jul 31, 2024

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
Copy link
Collaborator Author

gaby commented Jul 31, 2024

@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
Copy link
Collaborator Author

gaby commented Jul 31, 2024

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
Copy link
Owner

xyproto commented Jul 31, 2024

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
Copy link
Owner

xyproto commented Jul 31, 2024

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
Copy link
Collaborator Author

gaby commented Jul 31, 2024

@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
Copy link
Collaborator Author

gaby commented Jul 31, 2024

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
Copy link
Owner

xyproto commented Jul 31, 2024

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
Copy link
Collaborator Author

gaby commented Jul 31, 2024

@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
Copy link
Owner

xyproto commented Jul 31, 2024

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

@gaby
Copy link
Collaborator Author

gaby commented Jul 31, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants