labstack/echo

GitHub: labstack/echo

高性能、极简的 Go Web 框架,帮助开发者快速构建可扩展的 RESTful API 和 Web 服务。

Stars: 32283 | Forks: 2315

[![Sourcegraph](https://sourcegraph.com/github.com/labstack/echo/-/badge.svg?style=flat-square)](https://sourcegraph.com/github.com/labstack/echo?badge) [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/labstack/echo/v5) [![Go Report Card](https://goreportcard.com/badge/github.com/labstack/echo?style=flat-square)](https://goreportcard.com/report/github.com/labstack/echo) [![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/labstack/echo/echo.yml?style=flat-square)](https://github.com/labstack/echo/actions) [![Codecov](https://img.shields.io/codecov/c/github/labstack/echo.svg?style=flat-square)](https://codecov.io/gh/lab[![Sourcegraph](https://sourcegraph.com/github.com/labstack/echo/-/badge.svg?style=flat-square)](https://sourcegraph.com/github.com/labstack/echo?badge) [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/labstack/echo/v5) [![Go Report Card](https://goreportcard.com/badge/github.com/labstack/echo?style=flat-square)](https://goreportcard.com/report/github.com/labstack/echo) [![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/labstack/echo/echo.yml?style=flat-square)](https://github.com/labstack/echo/actions) [![Codecov](https://img.shields.io/codecov/c/github/labstack/echo.svg?style=flat-square)](https://codecov.io/gh/labstack/echo) [![Forum](https://img.shields.io/badge/community-forum-00afd1.svg?style=flat-square)](https://github.com/labstack/echo/discussions) [![Twitter](https://img.shields.io/badge/twitter-@labstack-55acee.svg?style=flat-square)](https://twitter.com/labstack) [![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/labstack/echo/master/LICENSE) ## Echo 高性能、可扩展、极简的 Go Web 框架。 * [官方网站](https://echo.labstack.com) * [快速开始](https://echo.labstack.com/docs/quick-start) * [中间件](https://echo.labstack.com/docs/category/middleware) 帮助与提问:[Github Discussions](https://github.com/labstack/echo/discussions) ### 功能概述 - 智能优先路由的优化 HTTP 路由器 - 构建健壮且可扩展的 RESTful API - 分组 API - 可扩展的中间件框架 - 在根、组或路由级别定义中间件 - JSON、XML 和表单 payload 的数据绑定 - 用于发送各种 HTTP 响应的便捷函数 - 集中式 HTTP 错误处理 - 使用任何模板引擎进行模板渲染 - 为 logger 自定义格式 - 高度可定制 - 通过 Let’s Encrypt 自动启用 TLS - 支持 HTTP/2 ## [指南](https://echo.labstack.com/guide) ### 支持的 Echo 版本 - 截至 2026-01-18,Echo 的最新主要版本为 `v5`。 - 有关 `v4` 和 `v5` 之间的公共 API 更改及升级说明,请参见 [API_CHANGES_V5.md](./API_CHANGES_V5.md)。 - Echo `v4` 的**安全***更新和 **Bug** 修复将支持到 **2026-12-31** ### 安装 ``` // go get github.com/labstack/echo/{version} go get github.com/labstack/echo/v5 ``` 最新版本的 Echo 支持最近的四个 Go 主要[版本](https://go.dev/doc/devel/release),并且可能兼容更旧的版本。 ### 示例 ``` 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!") } ``` # 官方中间件仓库 以下中间件列表由 Echo 团队维护。 | Repository | Description | |------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------| | [github.com/labstack/echo-jwt](https://github.com/labstack/echo-jwt) | [JWT](https://github.com/golang-jwt/jwt) 中间件 | | [github.com/labstack/echo-contrib](https://github.com/labstack/echo-contrib) | [casbin](https://github.com/casbin/casbin), [gorilla/sessions](https://github.com/gorilla/sessions), [pprof](https://pkg.go.dev/net/http/pprof)) 中间件 | | [github.com/labstack/echo-opentelemetry](https://github.com/labstack/echo-opentelemetry) | 用于链路追踪和指标的 [OpenTelemetry](https://opentelemetry.io/) 中间件 | | [github.com/labstack/echo-prometheus](https://github.com/labstack/echo-prometheus) | Echo 的 [Prometheus](https://github.com/prometheus/client_golang/) 中间件 | # 第三方中间件仓库 添加第三方中间件时请务必谨慎。Echo 团队没有足够的时间或人力来保证此列表中中间件的安全性和质量。 | Repository | Description | |------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [oapi-codegen/oapi-codegen](https://github.com/oapi-codegen/oapi-codegen) | 基于包含 [OpenAPI](https://swagger.io/specification/) 的 Client 和 Server 代码生成器,自动生成 RESTful API 文档 | | [github.com/swaggo/echo-swagger](https://github.com/swaggo/echo-swagger) | 使用 [Swagger](https://swagger.io/) 2.0 自动生成 RESTful API 文档。 | | [github.com/ziflex/lecho](https://github.com/ziflex/lecho) | 用于 Echo logger 接口的 [Zerolog](https://github.com/rs/zerolog) 日志库封装。 | | [github.com/brpaz/echozap](https://github.com/brpaz/echozap) | 用于 Echo logger 接口的 Uber´s [Zap](https://github.com/uber-go/zap) 日志库封装。 | | [github.com/samber/slog-echo](https://github.com/samber/slog-echo) | 用于 Echo logger 接口的 Go [slog](https://pkg.go.dev/golang.org/x/exp/slog) 日志库封装。 | | [github.com/darkweak/souin/plugins/echo](https://github.com/darkweak/souin/tree/master/plugins/echo) | 基于 [Souin](https://github.com/darkweak/souin) 的 HTTP 缓存系统,可自动缓存您的 endpoint。它根据您的需求支持多种分布式和非分布式存储系统。 | | [github.com/mikestefanello/pagoda](https://github.com/mikestefanello/pagoda) | 使用 Echo 构建的快速、易用的全栈 Web 开发入门套件。 | | [github.com/go-woo/protoc-gen-echo](https://github.com/go-woo/protoc-gen-echo) | ProtoBuf 生成 Echo 服务端代码 | 请提交 PR 以在此处添加您自己的库。 ## 贡献者 - [Vishal Rana](https://github.com/vishr) (作者) - [Nitin Rana](https://github.com/nr17) (顾问) - [Roland Lammel](https://github.com/lammel) (维护者) - [Martti T.](https://github.com/aldas) (维护者) - [Pablo Andres Fuente](https://github.com/pafuent) (维护者) - [贡献者](https://github.com/labstack/echo/graphs/contributors) ## 许可证 [MIT](https://github.com/labstack/echo/blob/master/LICENSE)
标签:API网关, DNS解析, Go语言, HTTP/2, HTTP路由, Let's Encrypt, RESTful API, Web框架, 中间件, 后端开发, 开源项目, 提示词优化, 数据绑定, 日志审计, 极简主义, 模板渲染, 程序破解, 网络编程, 错误处理