diff --git a/.gitignore b/.gitignore index 612bed1..a304ffd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ shelves.db shelves.db* -shelves +/shelves diff --git a/cmd/shelves/main.go b/cmd/shelves/main.go new file mode 100644 index 0000000..d15acf5 --- /dev/null +++ b/cmd/shelves/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "log" + "net/http" + + _ "github.com/mattn/go-sqlite3" + + "git.soup.land/soup/shelves/internal/db" + "git.soup.land/soup/shelves/internal/httpx" + "git.soup.land/soup/shelves/internal/routes" +) + +func main() { + 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") + } + + routes := routes.Routes(db) + fmt.Println("Listening on localhost:8999") + http.ListenAndServe("localhost:8999", httpx.Log(routes)) +}