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

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

  • 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,

  • 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/go-http-routing-benchmark@b5a1ebab84d686b0675a3c0c7d0b928a3b998d02

    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!

  • 读取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啊,为什么也被清空了呢?

  • 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改为直接定义就正常了?

  • 一个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

  • 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.

  • 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.
    
  • 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.

  • 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/ 做中间件,特别地控制它的权限。

:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron
: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

Aug 20, 2021
Dec 28, 2022
Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.

Ponzu Watch the video introduction Ponzu is a powerful and efficient open-source HTTP server framework and CMS. It provides automatic, free, and secur

Dec 28, 2022
Httpserver go - Server using only the go's libraries

API Rest Server This server use only the standard library of go (http, fmt and j

Jun 21, 2022
REST api using fiber framework written in golang and using firebase ecosystem to authentication, storage and firestore as a db and use clean architecture as base
REST api using fiber framework written in golang and using firebase ecosystem to authentication, storage and firestore as a db and use clean architecture as base

Backend API Example FiberGo Framework Docs : https://github.com/gofiber Info This application using firebase ecosystem Firebase Auth Cloud Storage Fir

May 31, 2022
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 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

Jan 5, 2023
Best simple, lightweight, powerful and really fast Api with Golang (Fiber, REL, Dbmate) PostgreSqL Database and Clean Architecture

GOLANG FIBER API (CLEAN ARCHITECTURE) Best simple, lightweight, powerful and really fast Api with Golang (Fiber, REL, Dbmate) PostgreSqLDatabase using

Sep 2, 2022
Flexible E-Commerce Framework on top of Flamingo. Used to build E-Commerce "Portals" and connect it with the help of individual Adapters to other services.

Flamingo Commerce With "Flamingo Commerce" you get your toolkit for building fast and flexible commerce experience applications. A demoshop using the

Dec 31, 2022
gin auto binding,grpc, and annotated route,gin 注解路由, grpc,自动参数绑定工具
gin auto binding,grpc, and annotated route,gin 注解路由, grpc,自动参数绑定工具

中文文档 Automatic parameter binding base on go-gin doc Golang gin automatic parameter binding Support for RPC automatic mapping Support object registrati

Jan 3, 2023
A quick and easy way to setup a RESTful JSON API

Go-Json-Rest A quick and easy way to setup a RESTful JSON API Go-Json-Rest is a thin layer on top of net/http that helps building RESTful JSON APIs ea

Jan 3, 2023
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/

Dec 6, 2022
hiboot is a high performance web and cli application framework with dependency injection support

Hiboot - web/cli application framework About Hiboot is a cloud native web and cli application framework written in Go. Hiboot is not trying to reinven

Nov 20, 2022
Package macaron is a high productive and modular web framework in Go.
Package macaron is a high productive and modular web framework in Go.

Macaron Package macaron is a high productive and modular web framework in Go. Getting Started The minimum requirement of Go is 1.6. To install Macaron

Jan 2, 2023
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

Nov 17, 2022
This library provides a simple framework of microservice, which includes a configurator, a logger, metrics, and of course the handler

Microservice The framework for the creation of microservices, written in Golang. (note: http microservice) Architecture microservice includes: handle

Dec 30, 2022
⚡ Rux is an simple and fast web framework. support middleware, compatible http.Handler interface. 简单且快速的 Go web 框架,支持中间件,兼容 http.Handler 接口

Rux Simple and fast web framework for build golang HTTP applications. NOTICE: v1.3.x is not fully compatible with v1.2.x version Fast route match, sup

Dec 8, 2022
Simple and lightweight Go web framework inspired by koa
Simple and lightweight Go web framework inspired by koa

VOX A golang web framework for humans, inspired by Koa heavily. Getting started Installation Using the go get power: $ go get -u github.com/aisk/vox B

Dec 14, 2022
A minimal framework to build web apps; with handler chaining, middleware support; and most of all standard library compliant HTTP handlers(i.e. http.HandlerFunc).
A minimal framework to build web apps; with handler chaining, middleware support; and most of all standard library compliant HTTP handlers(i.e. http.HandlerFunc).

WebGo v4.1.3 WebGo is a minimalistic framework for Go to build web applications (server side) with zero 3rd party dependencies. Unlike full-fledged fr

Jan 1, 2023