Giter Club home page Giter Club logo

Comments (6)

l3pp4rd avatar l3pp4rd commented on August 18, 2024

Hi, fastroute is built with minimal code to support url parameters and compose the routes, it basically can replace any http router with some customizations.

If you need extreme efficiency for context like parameters. You may copy the code and modify it so that you can add your own parameters instead just having path based parameters carried in request.

It depends on an use case, but using standar go context might be as well a reasonable decision, since it supports the deadline and cancellation.

from fastroute.

charbel14 avatar charbel14 commented on August 18, 2024

Thanks for the response.

I was thinking about modifying the parameters to allow for adding a custom one, but then I want to keep the distinction between path params, and middleware injected context values.

If I were to go the native context path:

func aMiddleware(routes ...fastroute.Router) fastroute.Router {
	return fastroute.RouterFunc(func(req *http.Request) http.Handler {
		for _, r := range routes {
			if h := r.Route(req); h != nil {
				ctx := req.Context()
				context.WithValue(ctx, "gateway", "myvalue")
				<req = req.WithContext(ctx)... ?>
				return h 
			}
		}
	})
}

Also something like:
fastroute.New("/:id/*", handler)
Does not seem to work. Is that a defect?

from fastroute.

l3pp4rd avatar l3pp4rd commented on August 18, 2024

it works as expected, you just need an argument name /:id/*rest would match

  • /1/anything to params ["id": "1", "rest": "/anything"]
  • /1/path/to/something to params ["id": "1", "rest": "/path/to/something"]

from fastroute.

charbel14 avatar charbel14 commented on August 18, 2024

Figured after going through the code. Thanks for the quick response. Would be nice to add an example for that case.

from fastroute.

l3pp4rd avatar l3pp4rd commented on August 18, 2024

There are enough examples for path matching in godoc package description, probably you haven't read it all

from fastroute.

charbel14 avatar charbel14 commented on August 18, 2024

Thanks.
Yes. I never looked at these docs. Was going through the readme and code.

I am thinking of adding a logger with latency per request.

from fastroute.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.