Add missing main.go

This commit is contained in:
soup 2024-11-16 18:34:39 -05:00
parent 3de890936d
commit 6de5f14a8d
No known key found for this signature in database
2 changed files with 32 additions and 1 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
shelves.db
shelves.db*
shelves
/shelves

31
cmd/shelves/main.go Normal file
View file

@ -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))
}