Lion - HTTP 路由器


MIT
跨平台
Google Go

软件简介

Lion 是一个 Go 语言的快速 HTTP 路由器,支持构建可伸缩的模块化的 REST APIs 应用。

特性

  • 上下文敏感 : Lion 使用事实标准 net/Context 用于存储路由参数并在中间件和 HTTP 处理器之间共享,可集成到 2016 Go 1.7 的标准库中.

  • 模块化 : 可轻松定义自己的模块实现可伸缩的架构

  • REST 友好 : 可定义模块将 HTTP 资源组合在一起.

  • 零分配 : Lion 不会产生垃圾

示例代码:

package main

import (
    "fmt"
    "net/http"

    "github.com/celrenheit/lion"
    "golang.org/x/net/context"
)

func Home(c context.Context, w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Home")
}

func Hello(c context.Context, w http.ResponseWriter, r *http.Request) {
    name := lion.Param(c, "name")
    fmt.Fprintf(w, "Hello "+name)
}

func main() {
    l := lion.Classic()
    l.GetFunc("/", Home)
    l.GetFunc("/hello/:name", Hello)
    l.Run()
}