Exemplo n.º 1
0
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)
	}
}
Exemplo n.º 2
0
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)

}
Exemplo n.º 3
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)
		}
	}
}