@@ -4,18 +4,13 @@ import (
44 "context"
55 "fmt"
66 log "github.com/Sirupsen/logrus"
7- _ "github.com/go-sql-driver/mysql"
8- "github.com/jmoiron/sqlx"
97 "github.com/qa-dev/jsonwire-grid/config"
108 "github.com/qa-dev/jsonwire-grid/handlers"
119 "github.com/qa-dev/jsonwire-grid/logger"
1210 "github.com/qa-dev/jsonwire-grid/middleware"
1311 "github.com/qa-dev/jsonwire-grid/pool"
1412 poolMetrics "github.com/qa-dev/jsonwire-grid/pool/metrics"
15- mysqlMigrations "github.com/qa-dev/jsonwire-grid/storage/migrations/mysql"
16- "github.com/qa-dev/jsonwire-grid/storage/mysql"
1713 "github.com/qa-dev/jsonwire-grid/utils/metrics"
18- "github.com/rubenv/sql-migrate"
1914 "net/http"
2015 "os"
2116 "os/signal"
@@ -29,27 +24,10 @@ func main() {
2924 cfg := config .New ()
3025 err := cfg .LoadFromFile (os .Getenv ("CONFIG_PATH" ))
3126 if err != nil {
32- log .Fatalf ("Problem in loading config from file, %s" , err . Error () )
27+ log .Fatalf ("Problem in loading config from file, %s" , err )
3328 }
3429 logger .Init (cfg .Logger )
3530
36- db , err := sqlx .Open ("mysql" , cfg .DB .Connection )
37- if err != nil {
38- log .Fatalf ("Database connection error: %s" , err .Error ())
39- }
40- storage := mysql .NewMysqlStorage (db )
41-
42- migrations := & migrate.AssetMigrationSource {
43- Asset : mysqlMigrations .Asset ,
44- AssetDir : mysqlMigrations .AssetDir ,
45- Dir : "storage/migrations/mysql" ,
46- }
47- n , err := migrate .Exec (db .DB , "mysql" , migrations , migrate .Up )
48- if err != nil {
49- log .Fatalf ("Migrations failed, %s" , err .Error ())
50- }
51- fmt .Printf ("Applied %d migrations!\n " , n )
52-
5331 statsdClient , err := metrics .NewStatsd (
5432 cfg .Statsd .Host ,
5533 cfg .Statsd .Port ,
@@ -58,13 +36,21 @@ func main() {
5836 cfg .Statsd .Enable )
5937
6038 if nil != err {
61- log .Errorf ("Statsd create socked error: %s" , err . Error () )
39+ log .Errorf ("Statsd create socked error: %s" , err )
6240 }
6341
6442 busyNodeDuration , err := time .ParseDuration (cfg .Grid .BusyNodeDuration )
6543 reservedNodeDuration , err := time .ParseDuration (cfg .Grid .BusyNodeDuration )
6644 if err != nil {
67- panic ("Invalid value grid.busy_node_duration in config" )
45+ log .Fatal ("Invalid value grid.busy_node_duration in config" )
46+ }
47+ storageFactory , err := invokeStorageFactory (* cfg )
48+ if err != nil {
49+ log .Fatalf ("Can't invoke storage factory, %s" , err )
50+ }
51+ storage , err := storageFactory .Create (* cfg )
52+ if err != nil {
53+ log .Fatalf ("Can't create storage factory, %s" , err )
6854 }
6955 poolInstance := pool .NewPool (storage )
7056 poolInstance .SetBusyNodeDuration (busyNodeDuration )
@@ -94,7 +80,7 @@ func main() {
9480 err = server .ListenAndServe ()
9581 if err != nil {
9682 // todo: норма ли что при закрытии всегда возвращается еррор???
97- log .Errorf ("Listen serve error, %s" , err . Error () )
83+ log .Errorf ("Listen serve error, %s" , err )
9884 }
9985 }()
10086
0 commit comments