Skip to content
This repository has been archived by the owner on Mar 21, 2019. It is now read-only.

Latest commit

 

History

History
63 lines (48 loc) · 1.33 KB

README.md

File metadata and controls

63 lines (48 loc) · 1.33 KB

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