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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 [Feature]: Export matching function #2138

Closed
3 tasks done
pjebs opened this issue Oct 5, 2022 · 11 comments 路 Fixed by #2142
Closed
3 tasks done

馃殌 [Feature]: Export matching function #2138

pjebs opened this issue Oct 5, 2022 · 11 comments 路 Fixed by #2142

Comments

@pjebs
Copy link
Contributor

pjebs commented Oct 5, 2022

Feature Description

Let say I have a route path like this: "/user/:name/books/:title".

I need the function used by fiber's router to check if a url matches that path.

Perhaps:

app.Use(func(c *fiber.Ctx) error {
	path := `/user/:name/books/:title`
	reqURL := string(c.Request().URI().Path())
	if Match(path, reqURL) {
		// Do something
	}
	return c.Next()
})

I believe the matching is done here: https://github.com/gofiber/fiber/blob/master/router.go#L64 (unexported)

Additional Context (optional)

Currently I am doing it like this as a workaround:

s.All(`/user/:name/books/:title`, func(c *fiber.Ctx) error {
	// Do something
	return c.Next()
})

This approach makes the path and all the methods end up in app.Stack().
Since I am essentially building middleware, I don't want it to appear as route(s).

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my suggestion prior to opening this one.
  • I understand that improperly formatted feature requests may be closed without explanation.
@ReneWerner87
Copy link
Member

we can make
I also had the thought

but is not so simple
and also not only the match function

before you can match this route you have to create a route first

for this there is an analysis function which is not really optimized because it was only used for the declaration of the routes so far

we would have to optimize this and then provide both functionalities and document how this can be used

@pjebs
Copy link
Contributor Author

pjebs commented Oct 5, 2022

I'm only interested in simpler functionality than what you envision.

I'm just trying to replace using s.All() as a workaround, because of the effects it has on Stack().

NOTE: The reason I'm asking for "obscure" functionality in my many feature requests is because I am making a package that combines fiber and sveltekit super-super tightly (tighter than it's ever been done before) and I need to interact with sveltekit's own rounting system.

I will open-source my package and demo it to everyone soon.

@ReneWerner87
Copy link
Member

This approach makes the path and all the methods end up in app.Stack().
Since I am essentially building middleware, I don't want it to appear as route(s).

sorry had overlooked the sentence

so you just don't want them to show up in stack ?

why not solve it differently by making this functionality filterable or overwriteable ?

@pjebs
Copy link
Contributor Author

pjebs commented Oct 5, 2022

I can't tell which paths are actual routes and which are from the "middleware" (app.All()). They both end up in the stack and are indistinguishable. They are also provided from outside my package that I don't control (i.e. the user/consumer of my package)

@ReneWerner87
Copy link
Member

ok

@pjebs pjebs mentioned this issue Oct 6, 2022
@pjebs
Copy link
Contributor Author

pjebs commented Nov 21, 2022

This is now complete.

@ReneWerner87 ReneWerner87 linked a pull request Nov 21, 2022 that will close this issue
@leonklingele
Copy link
Member

NOTE: The reason I'm asking for "obscure" functionality in my many feature requests is because I am making a package that combines fiber and sveltekit super-super tightly (tighter than it's ever been done before) and I need to interact with sveltekit's own rounting system.

I will open-source my package and demo it to everyone soon.

Sorry for abusing this issue to message you. Have you made any progress on this sveltekit-fiber package? I'm very interested!

@pjebs
Copy link
Contributor Author

pjebs commented Mar 26, 2023

@leonklingele I've made a lot of progress. I am looking for some help though. I can give a demo. We can meet up on zoom.

@leonklingele
Copy link
Member

@pjebs sent you an email, hope it's the correct address I used.

@pjebs
Copy link
Contributor Author

pjebs commented Apr 5, 2023

@leonklingele which email address? I didn't receive. Try planetpjs@hotmail.com

@pjebs
Copy link
Contributor Author

pjebs commented Apr 6, 2023

Oops: @leonklingele planetpjs@hotmail.com

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

Successfully merging a pull request may close this issue.

3 participants