GolangNote

Golang笔记

labstack/echo 是一个快速,不花俏的微型Go Web 框架

Permalink

labstack/echo 是一个快速,不花俏的微型Go Web 框架

特性

  • Fast HTTP router which smartly prioritize routes.
  • Extensible middleware, supports:
    • echo.MiddlewareFunc
    • func(echo.HandlerFunc) echo.HandlerFunc
    • echo.HandlerFunc
    • func(*echo.Context) error
    • func(http.Handler) http.Handler
    • http.Handler
    • http.HandlerFunc
    • func(http.ResponseWriter, *http.Request)
  • Extensible handler, supports:
    • echo.HandlerFunc
    • func(*echo.Context) error
    • http.Handler
    • http.HandlerFunc
    • func(http.ResponseWriter, *http.Request)
  • Sub-router/Groups
  • Handy functions to send variety of HTTP response:
    • HTML
    • HTML via templates
    • String
    • JSON
    • JSONP
    • XML
    • File
    • NoContent
    • Redirect
    • Error
  • Build-in support for:
    • Favicon
    • Index file
    • Static files
    • WebSocket
  • Centralized HTTP error handling.
  • Customizable HTTP request binding function.
  • Customizable HTTP response rendering function, allowing you to use any HTML template engine.

性能出众

Based on vishr/go-http-routing-benchmark, June 5, 2015.

GitHub API

Echo: 38662 ns/op, 0 B/op, 0 allocs/op

Performance

示例

Go: echo hello
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import (
    "net/http"

    "github.com/labstack/echo"
    mw "github.com/labstack/echo/middleware"
)

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

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

    // Middleware
    e.Use(mw.Logger())
    e.Use(mw.Recover())

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

    // Start server
    e.Run(":1323")
}

项目地址 labstack/echo

本文网址: https://golangnote.com/topic/55.html 转摘请注明来源

Related articles

Go 清理模块缓存

随着模块不断升级,时间久了,`pkg` 目录越来越大,导致专门为 Linux 下编译开的虚拟机空间爆满。...

Go Modules 使用备忘

简单说 Go Modules 就是包管理,从 go1.11 开始支持,可以不需要gopath存在,环境变量`GO111MODULE`,默认为 `auto` 项目存在 `go.mod` 则使用 go module ,否则使用GOPATH 和 vendor 机制。...

golang Web框架综合比较

下面是Square工程师对当时几个流行的golang Web 框架比较,可作为选择web 框架参考。...

Go 编程格言谚语

这些 go 格言谚语大多出自 Rob Pike 振奋人心的演讲视频,有很大参考价值。...

Write a Comment to "labstack/echo 是一个快速,不花俏的微型Go Web 框架"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.22.3 Processed in 0ms