forked from ebhomengo/niki
Merge pull request 'feat(niki): add migrate flag to main for running migrations' (#47) from stage/erfan/73-add-flag-to-main-for-migration into develop
Reviewed-on: ebhomengo/niki#47
This commit is contained in:
commit
93b0f51911
16
main.go
16
main.go
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
|
"git.gocasts.ir/ebhomengo/niki/adapter/redis"
|
||||||
"git.gocasts.ir/ebhomengo/niki/config"
|
"git.gocasts.ir/ebhomengo/niki/config"
|
||||||
httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server"
|
httpserver "git.gocasts.ir/ebhomengo/niki/delivery/http_server"
|
||||||
|
@ -17,9 +19,17 @@ type Dependencies struct {
|
||||||
initial.Services
|
initial.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseFlags() bool {
|
||||||
|
migrateFlag := flag.Bool("migrate", false, "perform database migration")
|
||||||
|
flag.Parse()
|
||||||
|
return *migrateFlag
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
migrate := parseFlags()
|
||||||
|
|
||||||
cfg := config.C()
|
cfg := config.C()
|
||||||
db := initDatabase(cfg)
|
db := initDatabase(cfg, migrate)
|
||||||
redisAdapter := initRedis(cfg)
|
redisAdapter := initRedis(cfg)
|
||||||
|
|
||||||
dependencies := initDependencies(cfg, redisAdapter, db)
|
dependencies := initDependencies(cfg, redisAdapter, db)
|
||||||
|
@ -68,8 +78,10 @@ func initAndRunServer(cfg config.Config, dependencies *Dependencies) {
|
||||||
server.Serve()
|
server.Serve()
|
||||||
}
|
}
|
||||||
|
|
||||||
func initDatabase(cfg config.Config) *mysql.DB {
|
func initDatabase(cfg config.Config, migrate bool) *mysql.DB {
|
||||||
|
if migrate {
|
||||||
migrateDatabase(cfg)
|
migrateDatabase(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
return initial.InitMysql(cfg)
|
return initial.InitMysql(cfg)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue