Ejemplo n.º 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)
		}
	}
}
Ejemplo n.º 2
0
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)
}
Ejemplo n.º 3
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)
	}
}
Ejemplo n.º 4
0
func init() {
	gae.Handle("/",
		web.SetErrorHandler(serveError,
			web.FormHandler(1000, true,
				web.NewRouter().
					Register("/", "GET", handleMainPage).
					Register("/sign", "POST", handleSign))))
}
Ejemplo n.º 5
0
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)
}
Ejemplo n.º 6
0
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)
}
Ejemplo n.º 7
0
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)
}
Ejemplo n.º 8
0
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)
}