-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🤔 Converts net/http request handlers to fiber request? #299
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you want to chat with us or need help, join us on our Discord server: https://gofiber.io/discord |
you can try something like this import (
"github.com/gofiber/fiber"
"github.com/valyala/fasthttp/fasthttpadaptor"
"net/http"
)
...
g.Get("/", WrapHandler(pprof.Index))
func WrapHandler(f func(http.ResponseWriter, *http.Request)) func(ctx *fiber.Ctx) {
return func(ctx *fiber.Ctx) {
fasthttpadaptor.NewFastHTTPHandler(http.HandlerFunc(f))(ctx.Fasthttp)
}
} |
@Shareed2k is right, the
So it is advisable using this function only for development but then convert the net/http handlers to fiber when going into production. |
Hey, thanks for the support. What I wanted to do was the opposite of that. I was able to do that by using an HTTP client calling the internal Fiber app. It's super cumbersome but solves the problem on the Cloud Functions case that strictly requires us to use
|
Is there any way to prevent that pprof dependency? |
pprof is just example |
Just submitted the PR adding the Google Cloud examples gofiber/recipes#16 |
@alvarowolfx, I'm happy you got this working. Too bad Google Cloud forces you to use a I will work on a simple adapter middleware for fiber when I have some spare time left. Thanks for sharing your problem and solution, I will mention this issue in an upcoming PS: @alvarowolfx are you able to listen on a second port? If so you could proxy the request to the fiber port. |
I'll take a look on starting it on a separated port and proxying the request, but I think the current workaround that I sent do almost that. But at least this is only required on Cloud functions, maybe on the recipes repo we encourage people to use app engine or cloud run for now, as this is not needed on those environments. |
Hi, is it "safe"/production-ready to use adaptor? Cheers, |
yes |
Question description
My use case is to user Fiber inside Google Cloud Functions or other places that enforce us to use the go
http.Handler
interface.The code snippet below is an example using
functions-framework-go
. I know that I can probably go ahead and use App Engine or Cloud Run, but would be interesting to support also Cloud Functions.Sorry if this is a silly question, I'm not that used to Go and I was trying to add more recipes to the repository and encourage people to use Fiber on all Google Cloud Go environments.
Code snippet
The text was updated successfully, but these errors were encountered: