diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 38b6d75c..3e2df162 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -50,22 +50,24 @@ func Execute() { } func runService() { - switch { - case util.Config.MySQL.IsPresent(): + store := createStore() + defer store.Close() + + dialect, err := util.Config.GetDialect() + if err != nil { + panic(err) + } + switch dialect { + case util.DbDriverMySQL: fmt.Printf("MySQL %v@%v %v\n", util.Config.MySQL.Username, util.Config.MySQL.Hostname, util.Config.MySQL.DbName) - case util.Config.BoltDb.IsPresent(): + case util.DbDriverBolt: fmt.Printf("BoltDB %v\n", util.Config.BoltDb.Hostname) - case util.Config.Postgres.IsPresent(): + case util.DbDriverPostgres: fmt.Printf("Postgres %v@%v %v\n", util.Config.Postgres.Username, util.Config.Postgres.Hostname, util.Config.Postgres.DbName) default: panic(fmt.Errorf("database configuration not found")) } - fmt.Printf("Tmp Path (projects home) %v\n", util.Config.TmpPath) - - store := createStore() - defer store.Close() - fmt.Printf("Semaphore %v\n", util.Version) fmt.Printf("Interface %v\n", util.Config.Interface) fmt.Printf("Port %v\n", util.Config.Port) @@ -89,7 +91,7 @@ func runService() { fmt.Println("Server is running") - err := http.ListenAndServe(util.Config.Interface+util.Config.Port, cropTrailingSlashMiddleware(router)) + err = http.ListenAndServe(util.Config.Interface+util.Config.Port, cropTrailingSlashMiddleware(router)) if err != nil { log.Panic(err) diff --git a/cli/cmd/user_change.go b/cli/cmd/user_change.go index 1a77d0fa..b989bfcc 100644 --- a/cli/cmd/user_change.go +++ b/cli/cmd/user_change.go @@ -35,7 +35,7 @@ func applyChangeUserArgsForUser(user db.User, store db.Store) { user.Name = targetUserArgs.name } - if targetUserArgs.admin == true { + if targetUserArgs.admin { user.Admin = true } diff --git a/db/factory/store.go b/db/factory/store.go index e9381e02..2b5a63c9 100644 --- a/db/factory/store.go +++ b/db/factory/store.go @@ -20,6 +20,6 @@ func CreateStore() db.Store { case util.DbDriverPostgres: return &sql.SqlDb{} default: - panic("Unsupported database dialect") + panic("Unsupported database dialect: " + config.Dialect) } } diff --git a/util/config.go b/util/config.go index d58abf09..478dcbda 100644 --- a/util/config.go +++ b/util/config.go @@ -276,8 +276,6 @@ func (conf *ConfigType) GetDBConfig() (dbConfig DbConfig, err error) { return } - dbConfig.Dialect = dialect - switch dialect { case DbDriverBolt: dbConfig = conf.BoltDb @@ -288,6 +286,9 @@ func (conf *ConfigType) GetDBConfig() (dbConfig DbConfig, err error) { default: err = errors.New("database configuration not found") } + + dbConfig.Dialect = dialect + return }