快速开始
Echo 是一个高性能、极简的 Go Web 框架。本指南会让服务器在五分钟内运行起来。
Echo 需要 Go 1.25 或更新版本。检查你的版本:
go version创建一个 module 并添加 Echo:
go mod init myappgo get github.com/labstack/echo/v5Hello, World
Section titled “Hello, World”创建 main.go:
package main
import ( "net/http"
"github.com/labstack/echo/v5" "github.com/labstack/echo/v5/middleware")
func main() { e := echo.New()
e.Use(middleware.RequestLogger()) e.Use(middleware.Recover())
e.GET("/", func(c *echo.Context) error { return c.JSON(http.StatusOK, map[string]string{"message": "Hello, World!"}) })
if err := e.Start(":1323"); err != nil { e.Logger.Error("failed to start server", "error", err) }}运行它:
go run main.go你的服务器已经在 http://localhost:1323 上运行。Echo 的路由器在每条路由分发请求时实现
零动态内存分配。