示例#1
0
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)
		}
	}
}
示例#2
0
文件: main.go 项目: rene-dev/twister
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)
	}
}
示例#3
0
func init() {
	gae.Handle("/",
		web.SetErrorHandler(serveError,
			web.FormHandler(1000, true,
				web.NewRouter().
					Register("/", "GET", handleMainPage).
					Register("/sign", "POST", handleSign))))
}
示例#4
0
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)
	}
}