dpouris / goster

🐹 Goster is a Go package to help you make micro-services and API's
MIT License
13 stars 0 forks source link

Enhance Dynamic Route Matching to Support Nested Paths #8

Closed dpouris closed 3 months ago

dpouris commented 3 months ago

The current implementation of the isDynamicRouteMatch function only supports dynamic routes with a depth of 1. This means it can correctly match routes like path/something/:var, but it fails to handle more deeply nested dynamic routes such as path/something/:var/:var2. To improve the flexibility and usability of the routing mechanism, we need to extend isDynamicRouteMatch to support multiple dynamic segments.

Goals:

  1. Support Nested Dynamic Routes:

    • Extend the isDynamicRouteMatch function to handle dynamic routes with multiple segments (e.g., path/something/:var/:var2).
  2. Improve Error Handling:

    • Enhance error handling to provide clear feedback when routes do not match or contain invalid patterns.

Tasks:

  1. Analyze Current Implementation:

    • Review the existing isDynamicRouteMatch function to identify areas that need changes to support nested routes.
  2. Extend Matching Logic:

    • Modify the regular expression and matching logic to support multiple dynamic segments in the route.
  3. Update Context Handling:

    • Ensure the context (Ctx) properly captures all dynamic parameters from nested routes.
  4. Refactor Route Construction:

    • Update constructPathRoutes and related functions to correctly handle nested dynamic routes.
  5. Add Tests:

    • Write comprehensive tests to cover various nested dynamic route scenarios.
    • Ensure tests validate both successful matches and appropriate error handling for unmatched routes.
  6. Update Documentation:

    • Update the documentation to reflect the changes and provide examples of nested dynamic routes.

Impact: Enhancing the isDynamicRouteMatch function to support nested dynamic routes will significantly improve the flexibility and power of the routing system. It will enable user to define more complex and deeply nested routes, making the package suitable for a wider range of use cases.

Priority: Medium-High

Estimated Effort: Medium

Dependencies:

Next Steps:

  1. Review the current isDynamicRouteMatch function and related routing logic.
  2. Modify the function to support nested dynamic routes.
  3. Develop and run tests to ensure the new functionality works as expected.
  4. Update the documentation with new examples and guidelines for using nested dynamic routes.