Golang笔记

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

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 https://github.com/vishr/go-http-routing-benchmark 23, June 5, 2015.

http://developer.github.com/v3 9

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

Performance

示例

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")
}

项目地址 https://github.com/labstack/echo 64

本文网址: https://golangnote.com/topic/55.html (转载注明出处)
关于GolangNote:记录在工作中使用golang 遇到、面临的相关问题及解决方法。如果你在这里获得一些知识或信息,解决你的编程问题,请考虑捐赠给不幸的人或者你喜欢的慈善机构,除捐赠外,种植树木、志愿服务或减少排碳的行为也很有益处。如果你有任何问题可以在下面 留言
Be the first to comment!
Captcha image
Relative Articles