Add missing main.go
This commit is contained in:
parent
3de890936d
commit
6de5f14a8d
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
shelves.db
|
shelves.db
|
||||||
shelves.db*
|
shelves.db*
|
||||||
shelves
|
/shelves
|
||||||
|
|
|
||||||
31
cmd/shelves/main.go
Normal file
31
cmd/shelves/main.go
Normal 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))
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue