Multiple application middleware support for tango
Go to file
Lunny Xiao 3e8d2563fc
Some checks failed
checks / check and test (push) Failing after 23s
Use actions instead of drone
2023-04-20 15:53:54 +08:00
.gitea/workflows Use actions instead of drone 2023-04-20 15:53:54 +08:00
README.md Use actions instead of drone 2023-04-20 15:53:54 +08:00
dispatch.go . 2015-06-28 12:53:08 +08:00
dispatch_test.go add Use() 2015-06-28 12:45:26 +08:00

Dispatch

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