This is only a mirror and Moved to https://gitea.com/lunny/tango

Overview

Tango 简体中文

CircleCI codecov Join the chat at https://img.shields.io/discord/323705316027924491.svg

Tango Logo

Package tango is a micro & pluggable web framework for Go.

Current version: v0.5.0 Version History

Getting Started

To install Tango:

go get github.com/lunny/tango

A classic usage of Tango below:

package main

import (
    "errors"
    "github.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()
}

Then visit http://localhost:8000 on your browser. You will get

{"say":"Hello tango!"}

If you change true after if to false, then you will get

{"err":"something error"}

This code will automatically convert returned map or error to a json because we has an embedded struct tango.JSON.

Features

  • Powerful routing & Flexible routes combinations.
  • Directly integrate with existing services.
  • Easy to plugin features with modular design.
  • High performance dependency injection embedded.

Middlewares

Middlewares allow you easily plugin features for your Tango applications.

There are already many middlewares to simplify your work:

Documentation

Discuss

Cases

License

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

Comments
  • index.html问题

    index.html问题

    http://gobook.io/read/github.com/go-tango/manual-zh-CN/chapter-06/ 文档中的 tg := tango.New() tg.Get("/index.html", tango.File("./public/index.html")) tg.Run() 这一部分不能正确访问到index.html

    当按以下运行时,当我访问"http://localhost:8080" 会跳转到index.html页面,而没有进入getHandler tg.Get("/", new(getHandler)) tg.Use(tango.Static(tango.StaticOptions{ RootPath: "./public/html", }))

    bug 
    opened by jettyu 4
  • I have questions about Social Auth lib

    I have questions about Social Auth lib

    Hi, Thank you for contributing to the community.

    Do you find it viable to use your authentication library? Https://github.com/go-tango/social-auth Well I see that it has been years that is not updated.

    Thanks,

    question 
    opened by marcuxyz 3
  • Tango routing broken?

    Tango routing broken?

    I'm currently preparing the next run of the the Go HTTP Routing Benchmark. Since several broken implementations were discovered already, I added a test validating the routing of each router earlier: julienschmidt/[email protected]02

    Unfortunately it seems like there is a problem with Tango:

        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /notifications/threads/:id
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /gists/:id
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected DELETE /gists/:id
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /repos/:owner/:repo/issues/:number
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /repos/:owner/:repo/milestones/:number
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /orgs/:org
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /teams/:id
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected DELETE /teams/:id
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /repos/:owner/:repo/pulls/:number
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /repos/:owner/:repo
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected DELETE /repos/:owner/:repo
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /repos/:owner/:repo/commits/:sha
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /repos/:owner/:repo/releases/:id
        routers_test.go:78: Tango in API GitHub: 404 - Not Found; expected GET /users/:user
        routers_test.go:78: Tango in API GPlus: 404 - Not Found; expected GET /people/:userId
        routers_test.go:78: Tango in API GPlus: 404 - Not Found; expected GET /activities/:activityId
        routers_test.go:78: Tango in API Parse: 404 - Not Found; expected GET /1/classes/:className
    

    I need your help to figure out what is broken and to fix it. The current implementation for Tango is here: Tango Implementation The complete list of routes can be found here: GitHub, GPlus, Parse

    Thanks in advance!

    opened by julienschmidt 3
  • 读取Form会清空body

    读取Form会清空body

    rbac中间件支持了动态权限定义之后,我在一个POST里死活读不到内容,调试了一个晚上,才发现下面这个问题。

    type Action struct {
    }
    func (a *Action) PermTag() string {
        flag := r.Context.Form("type")
        //根据flag返回不同权限要求
        bd, _ := r.Context.Body()
        fmt.Println(string(bd))
        //紧接着马上打印body,就已经是空了
    }
    

    反过来是可以正常读取到内容的,因此可以判断是第一句清空了body

    func (a *Action) PermTag() string {
        bd, _ := r.Context.Body()
        fmt.Println(string(bd))
        //此时body是有内容的
        flag := r.Context.Form("type")
        //根据flag返回不同权限要求
    }
    

    我只读取了form没有读body啊,为什么也被清空了呢?

    question 
    opened by qjebbs 2
  • Group时为什么路由为变量时会不识别,自动默认为第一个GET了

    Group时为什么路由为变量时会不识别,自动默认为第一个GET了

    t.Get("/", new(action.Index))
    t.Get("/:param", new(action.Index))
    
    logger.Info("AdminURL", config.DefaultAdminURL)
    // output: /admin
    t.Group(config.DefaultAdminURL, func(g *tango.Group) {
    
        g.Get("", new(master.Index))
        g.Get("/", new(master.Index))
        g.Get("/index", new(master.Index))
    
    })
    

    Group时为什么路由为变量时会不识别,自动默认为第一个GET了 但是把config.DefaultAdminURL改为直接定义就正常了?

    opened by lijunfeng 1
  • 一个return处理的问题

    一个return处理的问题

    在文件return.go中有这样一段:

    var result = ctx.Result
    if res, ok := ctx.Result.(*StatusResult); ok {
        ctx.WriteHeader(res.Code) //这里写了一次状态码
        result = res.Result
    }
    
    ...
    
    switch res := result.(type) {
    case AbortError, error:
        ctx.HandleError()
    case []byte:
        ctx.WriteHeader(http.StatusOK)
        ctx.Write(res)
    case string:
        ctx.WriteHeader(http.StatusOK) //这里写了第二次状态码
        ctx.Write([]byte(res))
    }
    

    如果有个action 是这样写的:

    func (a *Action) Get() (int, interface{}){
        return 201,"Created"
    }
    

    返回的却是200,而终端里会提示http: multiple response.WriteHeader calls

    opened by qjebbs 1
  • Sample implementation with xorm

    Sample implementation with xorm

    Hi, thank you for your great work. Is there sample implementation for tango and xorm? I am looking for best framework to make CMS server, work with javascript client and json. If you have it, please let me know. Thank you.

    opened by abeq 1
  • struct context maybe cause memory leak?

    struct context maybe cause memory leak?

    memory leak in this case:

       24.51MB  1.77% 20.68%   327.24MB 23.58%  net/http.readRequest
      258.23MB 18.61% 39.29%   283.23MB 20.41%  net/textproto.(*Reader).ReadMIMEHeader
    

    leak

    see more: https://github.com/gorilla/sessions see more: https://pathbox.github.io/2017/05/27/find-the-reason-memory-leak/

    Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with 
    context.ClearHandler or else you will leak memory! An easy way to do this is to wrap the top-level mux when calling http.ListenAndServe:
    
    http.ListenAndServe(":8080", context.ClearHandler(http.DefaultServeMux))
    The ClearHandler function is provided by the gorilla/context package.
    
    More examples are available on the Gorilla website.
    
    wait_for_investigate 
    opened by u0x01 1
  • Compitable with context.Context middlewares

    Compitable with context.Context middlewares

    Action is an interface in an middleware and context.Context is also an interface. Their are some similar feature between Action and context.Context. In tango, we use assert to get the info from Action, in context.Context, it's also a regular usage get info via assert.

    func (ctx *tango.Ctx) {
         if sess, ok := ctx.Action().(Sessioner); ok {
               // do something
        }
    }
    
    func (resp http.ResponseWriter, req *http.Request) {
        if sess, ok := req.Context().(Sessioner); ok {
              // do something 
       }
    }
    

    So that maybe all the tango's middlewares could be changed slightly to apply in http.Handler.

    opened by lunny 0
  • tango Group 与 Static 配合使用的问题

    tango Group 与 Static 配合使用的问题

    假设有以下代码

    t := tango.Classic()
    g := tango.NewGroup()
    g.Use(tango.Static(tango.StaticOptions{
        RootPath:   "./admin",
        Prefix:     "/",
        IndexFiles: []string{"index.html"},
    }))
    t.Group("/admin", g)
    t.Run(":80")
    

    运行后,无论访问http://localhost/还是http://localhost/admin/都是404。这个似乎不符合直觉。

    从这个代码来说,把 tango.StaticPrefix 设成/admin似乎也达成目的。但我这么做的初衷是希望给 http://localhost/admin/ 做中间件,特别地控制它的权限。

    enhancement 
    opened by qjebbs 1
Releases(v0.5.0)
Owner
Lunny Xiao
Lunny Xiao
:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron

Macaron Package macaron is a high productive and modular web framework in Go. Current version: 0.6.8 Getting Started The minimum requirement of Go is

ᴜɴᴋɴᴡᴏɴ 41 Aug 20, 2021
Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework Flamingo is a web framework based on Go. It is designed to build pluggable and maintainable web projects. It is production ready, f

Flamingo 316 Sep 18, 2022
A lightweight and fast http router from outer space

Alien Alien is a lightweight http router( multiplexer) for Go( Golang ), made for humans who don't like magic. Documentation docs Features fast ( see

Geofrey Ernest 123 Sep 26, 2022
:link: Generate HTML and CSS together, on the fly

On The Fly Package for generating HTML and CSS together, on the fly. Can also be used for generating HTML, XML or CSS (or templates). HTML and CSS can

Alexander F. Rødseth 42 Apr 21, 2022
A simple blog framework built with GO. Uses HTML files and a JSON dict to give you more control over your content.

Go-Blog A simple template based blog framework. Instructions Built for GO version: 1 See the Documentation or Getting Started pages in the wiki. Notes

Matt West 45 Sep 10, 2022
A small and evil REST framework for Go

go-rest A small and evil REST framework for Go Reflection, Go structs, and JSON marshalling FTW! go get github.com/ungerik/go-rest import "github.com/

Erik Unger 124 Sep 7, 2022
Fast and Reliable Golang Web Framework

Gramework The Good Framework Gramework long-term testing stand metrics screenshot made with Gramework Stats Dashboard and metrics middleware What is i

null 371 Sep 19, 2022
Mango is a modular web-application framework for Go, inspired by Rack, and PEP333.

Mango Mango is a modular web-application framework for Go, inspired by Rack and PEP333. Note: Not actively maintained. Overview Mango is most of all a

Paul Bellamy 369 Sep 14, 2022
Simple HTTP and REST client library for Go

Resty Simple HTTP and REST client library for Go (inspired by Ruby rest-client) Features section describes in detail about Resty capabilities Resty Co

Go Resty 6.7k Sep 22, 2022
An idiomatic Go REST API starter kit (boilerplate) following the SOLID principles and Clean Architecture

Go RESTful API Starter Kit (Boilerplate) This starter kit is designed to get you up and running with a project structure optimized for developing REST

Qiang Xue 998 Sep 27, 2022
Golang CTF framework and exploit development module

Golang CTF framework and exploit development module

Frank Hübner 14 Sep 15, 2022
Community built data connectors and processors for Spice.ai

data-components-contrib Community built data connectors and processors for Spice.ai The vision for data-components-contrib is a community-driven libra

Spice.ai 9 Sep 24, 2022
This is only a mirror and Moved to https://gitea.com/lunny/tango

Tango 简体中文 Package tango is a micro & pluggable web framework for Go. Current version: v0.5.0 Version History Getting Started To install Tango: go get

Lunny Xiao 836 Sep 27, 2022
Moved to https://gitea.com/lunny/gop

GOP 简体中文 GOP is a project manangement tool for building your golang applications out of global GOPATH. In fact gop will keep both global GOPATH and ev

Lunny Xiao 48 Oct 8, 2021
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm

xorm HAS BEEN MOVED TO https://gitea.com/xorm/xorm . THIS REPOSITORY WILL NOT BE UPDATED ANY MORE. 中文 Xorm is a simple and powerful ORM for Go. Featur

null 6.6k Sep 27, 2022
Moved https://gitea.com/xweb/xweb

xweb xweb是一个强大的Go语言web框架。 English 技术支持 QQ群:369240307 更新日志 v0.2.1 : 自动Binding新增对jquery对象,map和array的支持。 v0.2 : 新增 validation 子包,从 https://github.com/ast

null 65 Apr 21, 2022
Moved https://gitea.com/xweb/xweb

xweb xweb是一个强大的Go语言web框架。 English 技术支持 QQ群:369240307 更新日志 v0.2.1 : 自动Binding新增对jquery对象,map和array的支持。 v0.2 : 新增 validation 子包,从 https://github.com/ast

null 65 Apr 21, 2022
Mirror - Mirror is command line tool for mirroring a web page

mirror mirror is command line tool for mirroring a web page. Caution Do not abus

Yusuke Wada 10 May 29, 2022
:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron

Macaron Package macaron is a high productive and modular web framework in Go. Current version: 0.6.8 Getting Started The minimum requirement of Go is

ᴜɴᴋɴᴡᴏɴ 41 Aug 20, 2021
:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron

Macaron Package macaron is a high productive and modular web framework in Go. Current version: 0.6.8 Getting Started The minimum requirement of Go is

ᴜɴᴋɴᴡᴏɴ 41 Aug 20, 2021