Skip to content

A way to get current route? #1457

@buildpeak

Description

@buildpeak

Issue Description

Is there a better way to get the current route from a middleware or handler, other than this:

//MetricsMiddleware is a echo.Handler wrapper for Metrics
func (mr *MetricsRecorder) MetricsMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
    return func(c echo.Context) error {
        endpoint := "UNKNOWN"
        for _, r := range c.Echo().Routes() {
            if r.Method == c.Request().Method && r.Path == c.Path() {
                endpoint = r.Name
            }
        }

        err := next(c)
        ...
        return err
    }
}

Version/commit

v4.1.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions