-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (33 loc) · 1005 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
package main
import (
"log"
"net/http"
"time"
"github.com/ThomasCaud/go-rest-api/handler"
"github.com/ThomasCaud/go-rest-api/store"
"github.com/ThomasCaud/go-rest-api/store/postgres"
)
func main() {
database, err := store.InitializeDatabaseConnection()
if err != nil {
log.Fatal("Database connection failed: ", err.Error())
} else {
log.Println("Database connection succeed")
}
// Wait for db container to be ready
// todo wait via docker-compose
// Mon bin ne devrait pas être responsable de la gestion des migrations
// A supprimer et réutiliser ancienne version
// Les inserts: les faire via l'appel API (simple CURL en sh, python, go...)
time.Sleep(3 * time.Second)
err = store.ExecuteMigrations(database)
if err != nil {
log.Fatal("Migrations failed: ", err.Error())
}
var booksDbImpl = postgres.BooksDatabaseImpl{}
booksDbImpl.DB = database
app := &handler.App{
BooksDatabase: booksDbImpl,
}
log.Fatal(http.ListenAndServe(":3000", handler.GetRouter(app)))
}