generated from neverett8fr/go-service-template-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (45 loc) · 1.07 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"database/sql"
"log"
"salve-data-service/cmd"
application "salve-data-service/pkg/application/service"
"salve-data-service/pkg/config"
"github.com/gorilla/mux"
)
// Route declaration
func getRoutes(conn *sql.DB) *mux.Router {
r := mux.NewRouter()
application.NewServiceRoutes(r, conn)
return r
}
// Initiate web server
func main() {
conf, err := config.Initialise()
if err != nil {
log.Fatalf("error initialising config, err %v", err)
return
}
log.Println("config initialised")
serviceDB, err := cmd.OpenDB(&conf.DB)
if err != nil {
log.Fatalf("error starting db, err %v", err)
return
}
defer serviceDB.Close()
log.Println("connection to DB setup")
err = cmd.MigrateDB(serviceDB, conf.DB.Driver)
if err != nil {
log.Fatalf("error running DB migrations, %v", err)
return
}
log.Println("DB migrations ran")
router := getRoutes(serviceDB)
log.Println("API routes retrieved")
err = cmd.StartServer(&conf.Service, router)
if err != nil {
log.Fatalf("error starting server, %v", err)
return
}
log.Println("server started")
}