-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
44 lines (36 loc) · 771 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"errors"
"go-htmx-template/db"
"go-htmx-template/log"
"go-htmx-template/server"
"go-htmx-template/server/router"
"os"
"github.com/golang-migrate/migrate/v4"
)
func main() {
logger := log.New(
log.GetLevel(),
log.GetOutput(),
)
database, err := db.New(logger, "./db.sqlite3")
if err != nil {
logger.Error("Failed to create database", "error", err)
os.Exit(1)
}
defer database.Close()
if err = db.Migrate(database); err != nil && !errors.Is(err, migrate.ErrNoChange) {
logger.Error("failed to migrate database", "error", err)
return
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
svr := server.New(
logger,
":"+port,
server.WithRouter(router.New(logger, database)),
)
svr.StartAndWait()
}