Multiple application middleware support for tango
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.
Lunny Xiao 6535c1df1f
update CI config
2 years ago
README.md fixed example 4 years ago
circle.yml update CI config 2 years ago
dispatch.go . 4 years ago
dispatch_test.go add Use() 4 years ago

README.md

Dispatch Build Status

Dispacth is a handler for dipatch http request according url’s prefix.

Example

import (
    "github.com/lunny/tango"
    "github.com/tango-contrib/dispatch"
)

func main() {
    logger := tango.NewLogger(os.Stdout)
    t1 := tango.NewWithLog(logger)
    t2 := tango.NewWithLog(logger)

    dispatch := dispatch.New(map[string]*tango.Tango{
        "/": t1,
        "/api/": t2,
    })

    t3 := tango.NewWithLog(logger)
    t3.Use(dispatch)
    t3.Run(":8000")
}
package main

import (
    "github.com/Unknwon/macaron"
    "github.com/lunny/tango"
    "github.com/tango-contrib/dispatch"
)

func main() {

    t := tango.Classic()

    t.Any("/favicon.ico", func(self *tango.Context) {
        self.Redirect("/static/favicon.ico", 301)
    })
    t.Any("/", func() string {
        return "Hello Tango!"
    })

    m := macaron.Classic()
    m.Get("/", func(ctx *macaron.Context) string {
        return "Macaron on Tango!"
    })

    dispatch := dispatch.Use("/", t)
    dispatch.Add("/m/", m)

    tan := tango.Classic()
    tan.Use(dispatch)
    tan.Run(80)
}