func main() { logger := log.New(ioutil.Discard, "", 0) runtime.GOMAXPROCS(runtime.NumCPU()) web.Get("/(.*)", hello) web.SetLogger(logger) web.Run("0.0.0.0:8080") }
func main() { web.Get("/", indexPage) web.Post("/upload/(.*)", uploader) web.Get("/download/(.*)", downloader) bindHost := flag.String("bind", "0.0.0.0:8000", "bind to this address:port") realHost := flag.String("real-host", "", "real hostname client use to connect") realScheme := flag.String("real-scheme", "", "real scheme client use to connect") useXForwardedFor := flag.Bool("use-x-forwarded-for", false, "use X-Forwarded-For header for logging") logfile := flag.String("logfile", "", "log file (defaulg: stderr)") flag.Parse() appConfig = AppConfig{ *realScheme, *realHost, "http", *bindHost, *useXForwardedFor, } if *logfile != "" { web.SetLogger(NewRotateLog(*logfile, 1024*1024, 10, "", log.Ldate|log.Ltime)) } web.Run(appConfig.BindHost) }
func main() { f, _ := os.Create("server.log") logger := log.New(f, "", log.Ldate|log.Ltime) runtime.GOMAXPROCS(runtime.NumCPU()) web.Get("/(.*)", hello) web.SetLogger(logger) web.Run("0.0.0.0:8080") }
func main() { f, err := os.Create("server.log") if err != nil { println(err.Error()) return } logger := log.New(f, "", log.Ldate|log.Ltime) web.Get("/(.*)", hello) web.SetLogger(logger) web.Run("0.0.0.0:9999") }
func (s HTTPServer) Run(proto string) { logger := initLogger(Settings.Log.File) redis := &redis.Client{Addr: Settings.Redis.Addr(), Db: Settings.Redis.DB, Password: Settings.Redis.Password} var ( indexHandler = &IndexHandler{} restHandler = &RestQueueHandler{redis, logger} wsHandler = &WSQueueHandler{redis, logger} ) web.Get("/", indexHandler.Get) web.Get("/q", restHandler.List) web.Get("/q/(.+)", restHandler.Get) web.Post("/q/(.+)", restHandler.Put) web.Delete("/q/(.+)", restHandler.Clear) web.Get("/ws/(.+)", wsHandler.Consumer) web.SetLogger(logger) addr := Settings.HTTPServer.Addr() switch proto { case "http": web.Run(addr) case "fcgi": web.RunFcgi(addr) case "scgi": web.RunScgi(addr) default: flag.Usage() os.Exit(1) } }
func main() { //Get environment variables devStr := os.Getenv("REDUSEDEVELOPMODE") devMode = (devStr == "true") herokuProdStr := os.Getenv("REDUSE_HEROKU_PRODUCTION") herokuProduction = (herokuProdStr == "true") port := os.Getenv("PORT") //get the port that we are to run off of //get the database information from the environment dbName := os.Getenv("REDUSE_DB_NAME") dbAddress := os.Getenv("REDUSE_DB_ADDRESS") dbUsername := os.Getenv("REDUSE_DB_USERNAME") dbPassword := os.Getenv("REDUSE_DB_PASSWORD") //get the pertinent email information emailUsername := os.Getenv("REDUSE_EMAIL_USERNAME") emailPassword := os.Getenv("REDUSE_EMAIL_PASSWORD") adminEmails := os.Getenv("REDUSE_EMAIL_ADMIN_ADDRESSES") //Set up logging to stdout logger = log.New(os.Stdout, "", log.Lshortfile) web.SetLogger(logger) if devMode { logger.Println("Running in Develop mode") } if herokuProduction { logger.Println("Heroku Production flag set") } //Run startup code started, err := startup() if !started { logger.Println("Oops, looks like something went wrong with startup.") logger.Panic(err) return } //initialize the database (this also validates the database connection) err = initDatabase(dbName, dbAddress, dbUsername, dbPassword) if err != nil { logger.Println("Could not initialize database interface") logger.Panic(err.Error()) return } //Initialize the email sending functionality err = initEmail(adminEmails, emailUsername, emailPassword) if err != nil { logger.Println("Could not initialize email") logger.Panic(err.Error()) return } //Past this point, we should not have any panic()'s, rather any and all errors should be handled gracefully //don't do any of this stuff if we are in development mode (ie. production-only initialization goes here) if !devMode { //Set up the NewRelic agent agent := gorelic.NewAgent() agent.NewrelicLicense = os.Getenv("REDUSE_NEWRELIC_LICENSE_KEY") agent.NewrelicName = "Redu.se" agent.Run() } web.Get("/", home) web.Get("/page/disabled/?", showDisabled) web.Get("/page/terms/?", showTerms) web.Post("/page/generate/?", generate) web.Get("/page/report/?", reportLink) web.Post("/page/report/submit/?", submitReport) web.Get("/page/contact/?", contactPage) web.Post("/page/contact/submit/?", submitContact) web.Get("/rsrc/captcha/img/reload/(.+)\\.png", reloadCaptchaImage) web.Get("/rsrc/captcha/img/(.+)\\.png", serveCaptchaImage) //web.Get("/rsrc/captcha/audio/(.+)\\.wav", serveCaptchaAudio) web.Get("/(.+)/(.*)", serveLinkWithExtras) web.Get("/(.+)", serveLink) web.Run(":" + port) }