-
-
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
🚀 [Feature]: Expose Ctx.values #2118
Comments
Alternatively, is there a way to provide to the |
Hello @pjebs I noticed that the populating logic of Ctx.values is done when the route is matched in https://github.com/gofiber/fiber/blob/master/path.go#L438 and because the param of the route have changed, is it possible to use Internal redirect here? |
@li-jin-gou No because I need to do it from a middlware that has already been reached. After the middleware, another endpoint handler will handler the request. I need to modify the values before it reaches the eventual endpoint handler. If I do an internal redirect, the routing process will have to be performed again. That will be a performance hit but also defeat what I am trying to do cleanly. |
Any feedback on this issue. Is there any harm in exporting |
This is my current work-around: import "unsafe"
import "reflect"
routeParams := []string{} // route param names
values := [30]string{} // corresponding values
if len(routeParams) > 0 {
c.Route().Params = routeParams
val := reflect.Indirect(reflect.ValueOf(c))
ptrToValues := unsafe.Pointer(val.FieldByName("values").UnsafeAddr())
realPtrToValues := (*[30]string)(ptrToValues)
*realPtrToValues = values
} |
Can you give an example about necessarily of this feature? |
I'm building a framework that tightly couples SvelteKit and Fiber. (It's absoluetely amazing and almost finished) Sveltekit is designed for creating Front-End SPA. It's designed for JS in FE and Node for backend. You can't change the node requirement. I'm so impressed by SK, that I created a workaround that allows you to use Go (i.e. Fiber) for the backend so you get the best of both worlds. The way it works is I hijack SK and when it needs to make a call to Node, I instead make an AJAX call to Go. SK has it's own router with it's own syntax and parameters. I've designed my framework so that the Fiber handlers mirror the SK router. This feature request is about making my framework's Fiber Handler feel and operate like a normal Fiber despite it actually handling/serving a SK route. Therefore I need to load the route parameters using the workaround. |
Feature Description
It would be good to expose
values
inContext
.I need to intercept the request and modify the parameter values in a middleware.
The end route handler uses
c.Params(key)
. This method usesvalues
andc.route.Params
.I can already modify
c.route.Params
but I'm stuck due tovalues
.https://github.com/gofiber/fiber/blob/v2.37.1/ctx.go#L65
Additional Context (optional)
No response
Code Snippet (optional)
No response
Checklist:
The text was updated successfully, but these errors were encountered: