1
0
mirror of https://github.com/labstack/echo.git synced 2026-06-13 21:54:53 +02:00
Vishal Rana 4f5ac600f8 test: lock in v5 group route method-handling (405 + OPTIONS) (#3003)
* test: guard group catch-all against 405-masking and route shadowing

Adds regression tests around automatic group catch-all (404) route
registration. v5 removed that auto-registration; if it is restored
(e.g. PR #2996) these tests ensure it does not bring back the issues
that motivated the removal:

- wrong HTTP method on an existing group route must still return 405
  (with Allow header), not be masked to 404 by the catch-all;
- the group catch-all must not shadow concrete sibling routes, root
  routes, or other sibling groups' routes.

All four pass on current master (v5). The 405 test fails against the
restore-v4-behavior approach in #2996, pinning down that tradeoff.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test: rewrite group method-handling tests after review

Addresses review of the original regression file (PR #3003): its comments
described an automatic group catch-all "triggered by middleware" that does
not exist on master (v5), so the tests passed for the wrong reason and the
no-op middleware was inert.

Rewrite to assert v5's actual, verified behavior:
- method mismatch on a group route -> 405 with full Allow header
- OPTIONS on a registered group route -> 204 with Allow (preflight-relevant)
- concrete routes resolve; group prefix does not affect root routes

The 405 and OPTIONS tests are real gates: a group-level catch-all (manual or
the auto-registration proposed in #2996) masks both as 404, which these tests
would then catch. Drops the false premise, the inert middleware, and the
in-comment PR reference.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test: add rewritten group method-handling tests

The previous commit recorded only the deletion of the old file; this adds
the rewritten suite (group_method_handling_test.go).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test: add companion test demonstrating group catch-all masking

Addresses final review: converts the "verified empirically" comment into an
actual test. TestGroupRoute_catchAllMasksMethodHandling registers a group-wide
catch-all and asserts it masks both the 405 method-mismatch and the automatic
OPTIONS (204) response as 404 — the regression the 405/OPTIONS gate tests guard
against. Makes the rationale self-proving in-repo.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-13 12:44:20 -07:00
2016-11-16 21:26:56 -08:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-05-01 22:14:30 +03:00
2020-12-01 05:00:19 +00:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-05-02 01:51:23 +08:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00
2026-02-12 14:18:23 +02:00
2026-01-18 18:14:41 +02:00
2026-05-01 22:14:30 +03:00
2026-01-18 18:14:41 +02:00
2026-01-18 18:14:41 +02:00

Latest release Last commit Sourcegraph GoDoc Go Report Card GitHub Workflow Status (with event) Codecov Forum Twitter License

Echo

High performance, extensible, minimalist Go web framework.

Echo is built on Go's standard net/http — and interoperates with it via echo.WrapHandler / echo.WrapMiddleware — adding the parts the standard library leaves to you: a fast radix-tree router, request binding (with a pluggable validator), a deep middleware ecosystem, and centralized error handling. Actively maintained, with v5 as the current release line (see badges above for the latest version and most recent commit).

Help and questions: Github Discussions

Feature Overview

  • Optimized HTTP router which smartly prioritize routes
  • Build robust and scalable RESTful APIs
  • Group APIs
  • Extensible middleware framework
  • Define middleware at root, group or route level
  • Data binding for JSON, XML and form payload
  • Handy functions to send variety of HTTP responses
  • Centralized HTTP error handling
  • Template rendering with any template engine
  • Define your format for the logger
  • Highly customizable
  • Automatic TLS via Let’s Encrypt
  • HTTP/2 support

Sponsors


Click here for more information on sponsorship.

Guide

Supported Echo versions

  • Latest major version of Echo is v5 as of 2026-01-18.
    • See API_CHANGES_V5.md for public API changes between v4 and v5, notes on upgrading.
  • Echo v4 is supported with security* updates and bug fixes until 2026-12-31

See ROADMAP.md for where Echo is heading and the version support policy.

Installation

// go get github.com/labstack/echo/{version}
go get github.com/labstack/echo/v5

Latest version of Echo supports last four Go major releases and might work with older versions.

Example

package main

import (
  "github.com/labstack/echo/v5"
  "github.com/labstack/echo/v5/middleware"
  "log/slog"
  "net/http"
)

func main() {
  // Echo instance
  e := echo.New()

  // Middleware
  e.Use(middleware.RequestLogger()) // use the RequestLogger middleware with slog logger
  e.Use(middleware.Recover())       // recover panics as errors for proper error handling

  // Routes
  e.GET("/", hello)

  // Start server
  if err := e.Start(":8080"); err != nil {
    slog.Error("failed to start server", "error", err)
  }
}

// Handler
func hello(c *echo.Context) error {
  return c.String(http.StatusOK, "Hello, World!")
}

Official middleware repositories

Following list of middleware is maintained by Echo team.

Repository Description
github.com/labstack/echo-jwt JWT middleware
github.com/labstack/echo-contrib casbin, gorilla/sessions, pprof) middlewares
github.com/labstack/echo-opentelemetry OpenTelemetry middleware for tracing and metrics
github.com/labstack/echo-prometheus Prometheus middleware for Echo

Third-party middleware repositories

Be careful when adding 3rd party middleware. Echo teams does not have time or manpower to guarantee safety and quality of middlewares in this list.

Repository Description
oapi-codegen/oapi-codegen Automatically generate RESTful API documentation with OpenAPI Client and Server Code Generator
github.com/swaggo/echo-swagger Automatically generate RESTful API documentation with Swagger 2.0.
github.com/ziflex/lecho Zerolog logging library wrapper for Echo logger interface.
github.com/brpaz/echozap Uber´s Zap logging library wrapper for Echo logger interface.
github.com/samber/slog-echo Go slog logging library wrapper for Echo logger interface.
github.com/darkweak/souin/plugins/echo HTTP cache system based on Souin to automatically get your endpoints cached. It supports some distributed and non-distributed storage systems depending your needs.
github.com/mikestefanello/pagoda Rapid, easy full-stack web development starter kit built with Echo.
github.com/go-woo/protoc-gen-echo ProtoBuf generate Echo server side code

Please send a PR to add your own library here.

Contribute

Use issues for everything

  • For a small change, just send a PR.
  • For bigger changes open an issue for discussion before sending a PR.
  • PR should have:
    • Test case
    • Documentation
    • Example (If it makes sense)
  • You can also contribute by:
    • Reporting issues
    • Suggesting new features or enhancements
    • Improve/fix documentation

Credits

License

MIT

Languages
Go 99.9%