You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tango/README_CN.md

9.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

Tango English

Build Status badge Join the chat at https://img.shields.io/discord/323705316027924491.svg

Tango Logo

Tango 是一个微内核的Go语言Web框架采用模块化和注入式的设计理念。开发者可根据自身业务逻辑来选择性的装卸框架的功能甚至利用丰富的中间件来搭建一个全栈式Web开发框架。

特性

  • 强大而灵活的路由设计
  • 兼容已有的 http.Handler
  • 基于中间件的模块化设计,灵活定制框架功能
  • 高性能的依赖注入方式

安装Tango

go get gitea.com/lunny/tango

快速入门

一个经典的Tango例子如下

package main

import (
    "errors"

    "gitea.com/lunny/tango"
)

type Action struct {
    tango.JSON
}

func (Action) Get() interface{} {
    if true {
        return map[string]string{
            "say": "Hello tango!",
        }
    }
    return errors.New("something error")
}

func main() {
    t := tango.Classic()
    t.Get("/", new(Action))
    t.Run()
}

然后在浏览器访问http://localhost:8000, 将会得到一个json返回

{"say":"Hello tango!"}

如果将上述例子中的 true 改为 false, 将会得到一个json返回

{"err":"something error"}

这段代码因为拥有一个内嵌的tango.JSON所以返回值会被自动的转成Json

文档

交流讨论

使用案例

中间件列表

中间件可以重用代码并且简化工作:

License

This project is under BSD License. See the LICENSE file for the full license text.