Ejemplo n.º 1
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)

}
Ejemplo n.º 2
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)
	}
}