package main import ( "fmt" "log" "net/http" "os" _ "github.com/mattn/go-sqlite3" "shelves/backend/db" shelvesHttp "shelves/backend/http" "shelves/backend/routes" ) func main() { os.Remove("./shelves.db") db, migrateResult, err := db.Open("./shelves.db") if err != nil { log.Fatalf("Failed to open DB: %v", err) } if migrateResult.MigrationError != nil { log.Printf("An error was encountered while upgrading the database schema. You are on version %v, but the latest is %v. The error was: %v", migrateResult.SchemaVerNew, migrateResult.SchemaVerLatest, migrateResult.MigrationError) } schemaNeedsUpdating := migrateResult.SchemaVerNew != migrateResult.SchemaVerLatest if schemaNeedsUpdating { log.Printf("Your database schema needs to be updated. The application will continue to run, but you may encounter errors.\n") } _ = db routes := routes.Routes() fmt.Println("Listening on localhost:8999") http.ListenAndServe("localhost:8999", shelvesHttp.Log(shelvesHttp.WithCtx(db, routes))) }