Echo 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
Echo 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
Echo 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT
开发语言 Google Go 查看源码 »
操作系统 跨平台
软件类型 开源软件
所属分类 Web应用开发Web框架
开源组织
地区 不详
投 递 者 红薯
适用人群 未知
收录时间 2015-04-01

软件简介

Echo 是一个用 Go 语言开发的快速 HTTP 路由器(零内存分配)和微型 Web 框架。

性能比较:

 

特性:

  • Zippy router.

  • Extensible middleware/handler, supports:

    • func(*echo.Context)

    • http.Handler

    • http.HandlerFunc

    • func(http.ResponseWriter, *http.Request)

    • func(*echo.Context)

    • func(echo.HandlerFunc) echo.HandlerFunc

    • func(http.Handler) http.Handler

    • http.Handler

    • http.HandlerFunc

    • func(http.ResponseWriter, *http.Request)

    • Middleware

    • Handler

  • Handy encoding/decoding functions.

  • 支持静态文件处理

示例代码:

package main

import (
    "net/http"

    "github.com/labstack/echo"
    mw "github.com/labstack/echo/middleware"
    "github.com/rs/cors"
    "github.com/thoas/stats"
)

type user struct {
    ID   string `json:"id"`
    Name string `json:"name"`
}

var users map[string]user

func init() {
    users = map[string]user{
        "1": user{
            ID:   "1",
            Name: "Wreck-It Ralph",
        },
    }
}

func createUser(c *echo.Context) {
    u := new(user)
    if c.Bind(u) {
        users[u.ID] = *u
        c.JSON(http.StatusCreated, u)
    }
}

func getUsers(c *echo.Context) {
    c.JSON(http.StatusOK, users)
}

func getUser(c *echo.Context) {
    c.JSON(http.StatusOK, users[c.P(0)])
}

func main() {
    e := echo.New()

    //*************************//
    //   Built-in middleware   //
    //*************************//
    e.Use(mw.Logger)

    //****************************//
    //   Third-party middleware   //
    //****************************//
    // https://github.com/rs/cors
    e.Use(cors.Default().Handler)

    // https://github.com/thoas/stats
    s := stats.New()
    e.Use(s.Handler)
    // Route
    e.Get("/stats", func(c *echo.Context) {
        c.JSON(200, s.Data())
    })

    // Serve index file
    e.Index("public/index.html")

    // Serve static files
    e.Static("/js", "public/js")

    //************//
    //   Routes   //
    //************//
    e.Post("/users", createUser)
    e.Get("/users", getUsers)
    e.Get("/users/:id", getUser)

    // Start server
    e.Run(":8080")
}
展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击引领话题📣 发布并加入讨论🔥
发表了资讯
2016/11/16 07:16

Echo v3.0.0 beta3 发布,微型 Web 框架

Echo v3.0.0 beta.3 发布了,Echo 是一个用 Go 语言开发的快速 HTTP 路由器(零内存分配)和微型 Web 框架。 更新内容: 更新文档,自述文件和基准测试 修复 Bug 下载地址: Source code (zip) Source code (tar.gz)

0
11
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
0 评论
23 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部