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) } }
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) }
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) } } }
func main() { page = template.Must(template.New("index").Parse(body)) server.Run(":8080", web.NewRouter(). Register("/", "GET", index)) }
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) }
func init() { gae.Handle("/", web.SetErrorHandler(serveError, web.FormHandler(1000, true, web.NewRouter(). Register("/", "GET", handleMainPage). Register("/sign", "POST", handleSign)))) }
func main() { flag.Parse() h := web.NewRouter(). Register("/test", "GET", testHandler). Register("/gc", "GET", gcHandler). Register("/", "GET", expvar.ServeWeb) server.Run(":8080", h) }
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) }
func main() { chatTempl = template.Must(template.New("chat").Parse(chatStr)) go hub() server.Run(":8080", web.NewRouter(). Register("/", "GET", chatFrameHandler). Register("/ws", "GET", chatWsHandler)) }
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) }
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)) }
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) } }
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) }
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) } }
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) }
func main() { flag.Parse() var err os.Error if config.BlogUrl, err = url.Parse(fmt.Sprintf("%s://%s", *flagProtocol, *flagHost)); err != nil { panic("Invalid protocol and/or host") } // Cache. if *flagCache { config.Cache = lwb.NewCache() } else { config.Cache = lwb.NewDummyCache() } // Initialize the database. db, _ := store.NewJsonStore(config, nil) // Context for rendering. tags := db.GetTags() categories := db.GetCategories() sort.Strings(tags) sort.Strings(categories) context := &handlers.RenderContext{ Db: db, Config: config, Generator: *flagGenerator, RecentPosts: db.GetRecentPosts(config.NumRecentPosts), Tags: tags, Categories: categories, Archives: db.GetArchives(), UseCache: *flagCache, Title: config.Title, Path: config.BlogUrl.String(), } // Templates... handlers.ReloadTemplates(config) // Example of adding file extension types for static file serving. fileMimeTypes := map[string]string{ ".eot": "application/vnd.ms-fontobject", ".otf": "application/octet-stream", ".ttf": "application/x-font-ttf", ".woff": "application/x-font-woff", } // Expiry for static content. const maxAge = 60 * 60 * 24 * 365 * 10 fileHeaders := web.Header{ web.HeaderExpires: {fmt.Sprintf("%d", maxAge)}, web.HeaderCacheControl: {fmt.Sprintf("max-age=%d", maxAge)}, } serveFileOptions := &web.ServeFileOptions{fileMimeTypes, fileHeaders} // Register all path handlers. rh := handlers.DebugFilter(*flagDebug, config, web.NewRouter(). // Stats. Register("/expvar", "GET", web.HandlerFunc(expvar.ServeWeb)). // Example of redirecting old blog urls to shiny new ones. Register("/index.shtml", "GET", web.RedirectHandler("/", true)). Register("/index.html", "GET", web.RedirectHandler("/", true)). Register("/bionew.shtml", "GET", web.RedirectHandler("/page/bio", true)). Register("/blogarchives/<path:.*>.shtml", "GET", func(req *web.Request) { pathHandler(req, "%s://%s/%s") }). Register("/blogarchives/<path:[^0-9].*>", "GET", func(req *web.Request) { pathHandler(req, "%s://%s/category/%s") }). Register("/blogarchives/<path:[0-9].*>", "GET", func(req *web.Request) { pathHandler(req, "%s://%s/%s") }). // Example of redirecting to feedburner. //Register("/index.xml", "GET", web.RedirectHandler("http://feeds.feedburner.com/steve-lacey-main", false)). // Handlers. Register(config.MainIndexRegexp, "GET", handlers.MainIndexHandler(context)). Register(config.RssFeedRegexp, "GET", handlers.RssFeedHandler(context)). Register(config.MonthlyArchiveRegexp, "GET", handlers.DateArchiveHandler(context)). Register(config.YearlyArchiveRegexp, "GET", handlers.DateArchiveHandler(context)). Register(config.TagArchiveRegexp, "GET", handlers.TagArchiveHandler(context, func(key string) ([]*store.Post, bool) { return db.GetPostsByTag(key) })). Register(config.CategoryArchiveRegexp, "GET", handlers.TagArchiveHandler(context, func(key string) ([]*store.Post, bool) { return db.GetPostsByCategory(key) })). Register(config.PostRegexp, "GET", handlers.SinglePostHandler(context)). Register(config.PageRegexp, "GET", handlers.PageHandler(context)). Register(config.StaticRegexp, "GET", web.DirectoryHandler("static/", serveFileOptions))) // Create a logger. logFile, err := os.OpenFile(*flagLog, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) if err != nil { panic(fmt.Sprintf("Failed to open \"%s\": %s", *flagLog, err.String())) } defer logFile.Close() logger := server.NewApacheCombinedLogger(logFile) // Go! addr := fmt.Sprintf(":%d", *flagPort) fmt.Printf("Running on %s\n", addr) listener, err := net.Listen("tcp", addr) if err != nil { log.Fatal("Listen", err) return } defer listener.Close() err = (&server.Server{Listener: listener, Handler: rh, Logger: logger}).Serve() if err != nil { log.Fatal("Server", err) } }
func main() { h := web.NewRouter().Register("/", "GET", serveHello) server.Run(":8080", h) }
func main() { router := web.NewRouter(). Register("/<txt>/<num:[0-9]+>", "GET", ServeHTTP) server.Run(":8080", router) }