func main() { DB, err := crud.Connect("mysql", os.Getenv("DATABASE_URL")) if err != nil { panic(err) } if err := DB.CreateTables(User{}); err != nil { panic(err) } tx, err := DB.Begin() if err != nil { panic(err) } azer := User{ FirstName: "Azer", LastName: "Koculu", } if err := tx.Create(&azer); err != nil { panic(err) } tx.Commit() copy := User{} if err := DB.Read(©, "WHERE first_name='Azer'"); err != nil { panic(err) } fmt.Println(copy.Id) }
func main() { logger = log.NewLogfmtLogger(os.Stderr) logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) logger.Log("msg", "Starting bikefinder") var err error db_url := os.Getenv("DATABASE_URL") DB, err = crud.Connect("mysql", db_url) if err != nil { logger.Log("msg", "Failed to connect to db at "+db_url, "error", err) panic(err) } err = DB.CreateTables(DockingStationStatus{}) if err != nil { logger.Log("msg", "Failed to create db table", "error", err) panic(err) } http.HandleFunc("/schemes", getSchemes) http.HandleFunc("/stations", getStationsInside) http.HandleFunc("/bikes-near", getBikesNear) http.HandleFunc("/freedocks-near", getFreeDocksNear) http.HandleFunc("/map", getMap) http.HandleFunc("/ingest", ingest) http.Handle("/", http.FileServer(http.Dir("./static"))) bind := fmt.Sprintf("%s:%s", os.Getenv("OPENSHIFT_GO_IP"), os.Getenv("OPENSHIFT_GO_PORT")) logger.Log("msg", "Attempting to listen on "+bind) err = http.ListenAndServe(bind, nil) if err != nil { logger.Log("msg", "Failed to listen", "error", err) panic(err) } }
func init() { var err error DB, err = crud.Connect("mysql", os.Getenv("DATABASE_URL")) if err != nil { panic(err) } }
func OpenDB() error { var err error DB, err = crud.Connect("mysql", os.Getenv("DATABASE_URL")) return err }