// main connects to the database, sets up request routing, and starts the http server. func main() { var err error db, err = sql.Open("postgres", config.DataBase.Postgres()) if err != nil { log.Fatalf("ERROR: problem with DB config: %s", err) } defer db.Close() db.SetMaxIdleConns(config.DataBase.MaxIdleConns) db.SetMaxOpenConns(config.DataBase.MaxOpenConns) err = db.Ping() if err != nil { log.Println("Error: problem pinging DB - is it up and contactable? 500s will be served") } // For map zoom regions other than NZ will need to read some config from somewhere. wm, err = map180.Init(db, map180.Region(`newzealand`), 256000000) if err != nil { log.Fatalf("ERROR: problem with map180 config: %s", err) } http.Handle("/", handler()) log.Fatal(http.ListenAndServe(":"+config.WebServer.Port, nil)) }
func main() { var err error db, err = sql.Open("postgres", os.ExpandEnv("host=${DB_HOST} connect_timeout=30 user=${DB_USER} password=${DB_PASSWORD} dbname=mtr sslmode=disable")) if err != nil { log.Println("Problem with DB config.") log.Fatal(err) } defer db.Close() db.SetMaxIdleConns(30) db.SetMaxOpenConns(30) if err = db.Ping(); err != nil { log.Println("ERROR: problem pinging DB - is it up and contactable? 500s will be served") } dbR, err = sql.Open("postgres", os.ExpandEnv("host=${DB_HOST} connect_timeout=30 user=${DB_USER_R} password=${DB_PASSWORD_R} dbname=mtr sslmode=disable")) if err != nil { log.Println("Problem with DB config.") log.Fatal(err) } defer dbR.Close() dbR.SetMaxIdleConns(30) dbR.SetMaxOpenConns(30) if err = dbR.Ping(); err != nil { log.Println("ERROR: problem pinging DB - is it up and contactable? 500s will be served") } // For map zoom regions other than NZ will need to read some config from somewhere. wm, err = map180.Init(dbR, map180.Region(`newzealand`), 256000000) if err != nil { log.Printf("ERROR: problem with map180 config: %s", err.Error()) } go deleteMetrics() log.Println("starting server") log.Fatal(http.ListenAndServe(":8080", inbound(mux))) }