本文整理匯總了Golang中github.com/garyburd/twister/web.NewRouter函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewRouter函數的具體用法?Golang NewRouter怎麽用?Golang NewRouter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewRouter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
flag.Parse()
h := web.SetErrorHandler(coreErrorHandler,
web.ProxyHeaderHandler("X-Real-Ip", "X-Scheme",
web.NewRouter().
Register("/debug/<:.*>", "*", web.NewRouter().
Register("/debug/expvar", "GET", expvar.ServeWeb).
Register("/debug/pprof/<:.*>", "*", pprof.ServeWeb)).
Register("/<:.*>", "*", web.FormHandler(10000, true, web.NewRouter().
Register("/", "GET", homeHandler).
Register("/core/file", "GET", web.FileHandler("static/file.txt", nil)).
Register("/static/<path:.*>", "GET", web.DirectoryHandler("static/", nil)).
Register("/chat", "GET", chatFrameHandler).
Register("/chat/ws", "GET", chatWsHandler).
Register("/mp", "GET", mpGetHandler, "POST", mpPostHandler).
Register("/debug/pprof/<command>", "*", web.HandlerFunc(pprof.ServeWeb)).
Register("/core/", "GET", coreHandler).
Register("/core/a/<a>/", "GET", coreHandler).
Register("/core/b/<b>/c/<c>", "GET", coreHandler).
Register("/core/c", "POST", coreHandler)))))
listener, err := net.Listen("tcp", ":8080")
if err != nil {
log.Fatal("Listen", err)
return
}
defer listener.Close()
err = (&server.Server{Listener: listener, Handler: h, Logger: server.LoggerFunc(server.VerboseLogger)}).Serve()
if err != nil {
log.Fatal("Server", err)
}
}
示例2: main
func main() {
flag.Parse()
if *initdb {
loadFirstRecord()
return
}
var portString = fmt.Sprintf(":%d", *port)
h := web.ProcessForm(10000, true, // limit size of form to 10k, enable xsrf
web.NewRouter().
Register("/debug/<:.*>", "*", web.NewRouter().
Register("/debug/expvar", "GET", expvar.ServeWeb).
Register("/debug/pprof/<:.*>", "*", pprof.ServeWeb)).
Register("/static/<path:.*>", "GET", web.DirectoryHandler("static/", &web.ServeFileOptions{})).
Register("/favicon.ico", "GET", web.FileHandler("static/favicon.ico", &web.ServeFileOptions{})).
Register("/rss/<feed:(.*)>", "GET", rssHandler).
Register("/", "GET", homeHandler).
Register("/category/<category:(.*)>", "GET", categoryHandler).
Register("/tags/<tag:(.*)>", "GET", tagsHandler).
Register("/edit/<path:(.*)>", "GET", editHandler, "POST", saveHandler).
Register("/search", "POST", searchHandler, "GET", searchHandler).
Register("/<path:(.*)>", "GET", viewHandler))
server.Run(portString, h)
}
示例3: main
func main() {
flag.Parse()
r := web.NewRouter().
Register("/", "*", web.FormHandler(-1, false, web.HandlerFunc(handler))).
Register("/static/<path:.*>", "GET", web.DirectoryHandler("static/", nil)).
Register("/example/file.txt", "GET", web.FileHandler("static/file.txt", nil)).
Register("/urlparam/<a>/<b>", "GET", handler).
Register("/panic/before", "GET", web.HandlerFunc(panicBeforeResponse)).
Register("/panic/after", "GET", web.HandlerFunc(panicAfterResponse)).
Register("/limit", "POST", web.FormHandler(16, false, web.HandlerFunc(handler))).
Register("/xsrf", "*", web.FormHandler(-1, true, web.HandlerFunc(handler))).
Register("/multipart", "POST", multipartHandler).
Register("/debug/expvar", "GET", expvar.ServeWeb).
Register("/debug/pprof/<:.*>", "*", pprof.ServeWeb).
Register("/proxy", "GET", web.ProxyHeaderHandler("X-Real-Ip", "X-Scheme", web.HandlerFunc(handler)))
h := web.SetErrorHandler(errorHandler, r)
if *useAdapter {
log.Print("Running with adapter.")
if err := http.ListenAndServe(*addr, adapter.HTTPHandler{h}); err != nil {
log.Fatal(err)
}
} else {
listener, err := net.Listen("tcp", *addr)
if err != nil {
log.Fatal("Listen", err)
}
defer listener.Close()
if err := (&server.Server{Listener: listener, Handler: h, Logger: server.LoggerFunc(server.VerboseLogger)}).Serve(); err != nil {
log.Fatal(err)
}
}
}
示例4: main
func main() {
page = template.Must(template.New("index").Parse(body))
server.Run(":8080",
web.NewRouter().
Register("/", "GET", index))
}
示例5: main
func main() {
db, db_err = mysql.DialTCP("localhost", "root", "asd123", "orders")
if db_err != nil {
log.Println(db_err)
os.Exit(1)
}
port := ":8080"
if envPort := os.Getenv("ORDERS_PORT"); envPort != "" {
port = envPort
}
h := web.FormHandler(10000, false,
web.NewRouter().
Register("/", "GET", indexHandler).
Register("/company/create", "GET", createCompanyFormHandler, "POST", createCompanyHandler).
Register("/company/", "GET", viewCompanyHandler).
Register("/order/create", "GET", createOrderFormHandler, "POST", createOrderHandler).
Register("/order/", "GET", viewOrderHandler).
Register("/event/create", "POST", createEventHandler).
Register("/customer/create", "POST", createCustomerHandler).
Register("/customer/", "GET", viewCustomerHandler).
Register("/customer/paid/", "GET", paidHandler).
Register("/line/create", "POST", createLineHandler).
Register("/static/<path:.*>", "GET", web.DirectoryHandler("./static/", new(web.ServeFileOptions))))
server.Run(port, h)
}
示例6: init
func init() {
gae.Handle("/",
web.SetErrorHandler(serveError,
web.FormHandler(1000, true,
web.NewRouter().
Register("/", "GET", handleMainPage).
Register("/sign", "POST", handleSign))))
}
示例7: main
func main() {
flag.Parse()
h := web.NewRouter().
Register("/test", "GET", testHandler).
Register("/gc", "GET", gcHandler).
Register("/", "GET", expvar.ServeWeb)
server.Run(":8080", h)
}
示例8: main
func main() {
const titleParam = "<title:[a-zA-Z0-9]+>"
h := web.FormHandler(10000, true, // limit size of form to 10k, enable xsrf
web.NewRouter().
Register("/view/"+titleParam, "GET", viewHandler).
Register("/edit/"+titleParam, "GET", editHandler, "POST", saveHandler))
server.Run(":8080", h)
}
示例9: main
func main() {
chatTempl = template.Must(template.New("chat").Parse(chatStr))
go hub()
server.Run(":8080",
web.NewRouter().
Register("/", "GET", chatFrameHandler).
Register("/ws", "GET", chatWsHandler))
}
示例10: main
func main() {
flag.Parse()
readSettings()
h := web.FormHandler(10000, true, web.NewRouter().
Register("/", "GET", home).
Register("/login", "GET", login).
Register("/callback", "GET", authCallback))
server.Run(":8080", h)
}
示例11: main
func main() {
chatTempl = template.New(template.FormatterMap{"": template.HTMLFormatter})
chatTempl.SetDelims("{{", "}}")
if err := chatTempl.Parse(chatStr); err != nil {
panic("template error: " + err.String())
}
go hub()
server.Run(":8080",
web.NewRouter().
Register("/", "GET", chatFrameHandler).
Register("/ws", "GET", chatWsHandler))
}
示例12: main
func main() {
submitRoute := "/ajax/submit.json"
statusRoute := "/ajax/status/<id:[^.]+>.json"
router := web.NewRouter().
Register("/", "GET", homeHandler).
Register("/static/bookmarklet.js", "GET", handleBookmarklet).
Register("/static/<path:.*>", "GET", web.DirectoryHandler("static", nil)).
Register("/<page:(faq|bugs|contact)>", "GET", pageHandler).
Register("/<chunk:(firefox|safari|chrome|ie|ios|kindle-email)>", "GET", chunkHandler).
Register(submitRoute, "GET", submitHandler).
Register(statusRoute, "GET", statusHandler).
Register("/debug.json", "GET", expvar.ServeWeb).
Register("/debug/pprof/<:.*>", "*", pprof.ServeWeb)
redirector := web.NewRouter().
// These routes get matched in both places so they work everywhere.
Register(submitRoute, "GET", submitHandler).
Register(statusRoute, "GET", statusHandler).
Register("/<splat:>", "GET", redirectHandler)
hostRouter := web.NewHostRouter(redirector).
Register(canonicalHost, router)
listener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%s", port))
if err != nil {
logger.Fatalf("Failed to listen: %s", err)
}
defer listener.Close()
server := &server.Server{
Listener: listener,
Handler: hostRouter,
Logger: server.LoggerFunc(ShortLogger),
}
err = server.Serve()
if err != nil {
logger.Fatalf("Failed to server: %s", err)
}
}
示例13: main
func main() {
/*
log.Println(splitTags("Nick Carolyn Vanessa Hannah"))
log.Println(splitTags("\"Hello World\""))
log.Println(splitTags("\"@Carolyn Gerakines\" #dinner #date"))
log.Println(splitTags("#meeting \"@Steve McGarrity\" #port #battle.net \"\""))
log.Println(splitTags("#api-wow +3h"))
*/
session, session_err = mgo.Mongo("localhost")
if session_err != nil {
panic(session_err)
}
defer session.Close()
db, db_err = mysql.DialTCP("localhost", "root", "asd123", "gobook")
if db_err != nil {
log.Println(db_err)
os.Exit(1)
}
port := ":8080"
if envPort := os.Getenv("GOBOOK_PORT"); envPort != "" {
port = envPort
}
h := web.FormHandler(10000, false,
web.NewRouter().
Register("/", "GET", displayIndex, "POST", createEntry).
Register("/view/<entry:.*>", "GET", displayEntry).
Register("/thread/<id:.*>", "GET", displayThread).
Register("/calendar", "GET", displayCalendar).
Register("/calendar/<year:.*>/<month:.*>/<day:.*>", "GET", displayDay).
Register("/calendar/<year:.*>/<month:.*>", "GET", displayMonth).
Register("/calendar/<year:.*>", "GET", displayYear).
// Register("/migrate", "GET", migrate).
Register("/archive", "GET", displayArchive).
Register("/tag/<tag:.*>", "GET", displayTag).
// Register("/entry/<id:.*>", "GET", displayEntry).
Register("/api/tag/rename/", "POST", renameTag).
Register("/summary/<year:.*>/<month:.*>", "GET", displayMonth).
Register("/static/<path:.*>", "GET", web.DirectoryHandler("./static/", new(web.ServeFileOptions))))
server.Run(port, h)
}
示例14: main
func main() {
flag.Parse()
h := web.SetErrorHandler(coreErrorHandler,
web.ProcessForm(10000, true, web.NewHostRouter(nil).
Register("www.example.com", web.NewRouter().
Register("/", "GET", homeHandler).
Register("/chat", "GET", chatFrameHandler).
Register("/chat/ws", "GET", chatWsHandler).
Register("/core/", "GET", coreHandler).
Register("/core/a/<a>/", "GET", coreHandler).
Register("/core/b/<b>/c/<c>", "GET", coreHandler).
Register("/core/c", "POST", coreHandler))))
err := server.ListenAndServe("localhost:8080", ":8080", h)
if err != nil {
log.Exit("ListenAndServe:", err)
}
}
示例15: main
func main() {
/* log.Println(splitTags("Nick Carolyn Vanessa Hannah"))
log.Println(splitTags("\"Hello World\""))
log.Println(splitTags("\"@Carolyn Gerakines\" #dinner #date"))
log.Println(splitTags("#meeting \"@Steve McGarrity\" #port #battle.net \"\"")) */
db, db_err = mysql.DialTCP("localhost", "root", "asd123", "gobook")
if db_err != nil {
log.Println(db_err)
os.Exit(1)
}
port := ":8080"
if envPort := os.Getenv("GOBOOK_PORT"); envPort != "" {
port = envPort
}
h := web.FormHandler(10000, false,
web.NewRouter().
Register("/", "GET", displayIndex, "POST", createEntry).
Register("/archive", "GET", displayArchive).
Register("/static/<path:.*>", "GET", web.DirectoryHandler("./static/", new(web.ServeFileOptions))))
server.Run(port, h)
}