refactor(config): add field dialect

This commit is contained in:
Denis Gukov 2021-08-28 21:24:54 +05:00
parent 31a71abf4a
commit 0b3b56620c
4 changed files with 17 additions and 14 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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
}