erenJag 5 rokov pred
rodič
commit
07ca331df5
1 zmenil súbory, kde vykonal 9 pridanie a 6 odobranie
  1. 9 6
      pkg/database/database.go

+ 9 - 6
pkg/database/database.go

@@ -29,23 +29,23 @@ type Context struct {
 func checkConfig(cfg map[string]string) error {
 func checkConfig(cfg map[string]string) error {
 	switch dbType, _ := cfg["type"]; dbType {
 	switch dbType, _ := cfg["type"]; dbType {
 	case "sqlite":
 	case "sqlite":
-		if val, ok := cfg["db_path"]; !ok && val == "" {
+		if val, ok := cfg["db_path"]; !ok || val == "" {
 			return fmt.Errorf("please specify a 'db_path' to SQLite db in the configuration")
 			return fmt.Errorf("please specify a 'db_path' to SQLite db in the configuration")
 		}
 		}
 	case "mysql":
 	case "mysql":
-		if val, ok := cfg["db_host"]; !ok && val == "" {
+		if val, ok := cfg["db_host"]; !ok || val == "" {
 			return fmt.Errorf("please specify a 'db_host' to SQLite db in the configuration")
 			return fmt.Errorf("please specify a 'db_host' to SQLite db in the configuration")
 		}
 		}
 
 
-		if val, ok := cfg["db_username"]; !ok && val == "" {
+		if val, ok := cfg["db_username"]; !ok || val == "" {
 			return fmt.Errorf("please specify a 'db_username' to SQLite db in the configuration")
 			return fmt.Errorf("please specify a 'db_username' to SQLite db in the configuration")
 		}
 		}
 
 
-		if val, ok := cfg["db_password"]; !ok && val == "" {
+		if val, ok := cfg["db_password"]; !ok || val == "" {
 			return fmt.Errorf("please specify a 'db_password' to SQLite db in the configuration")
 			return fmt.Errorf("please specify a 'db_password' to SQLite db in the configuration")
 		}
 		}
 
 
-		if val, ok := cfg["db_name"]; !ok && val == "" {
+		if val, ok := cfg["db_name"]; !ok || val == "" {
 			return fmt.Errorf("please specify a 'db_name' to SQLite db in the configuration")
 			return fmt.Errorf("please specify a 'db_name' to SQLite db in the configuration")
 		}
 		}
 	default:
 	default:
@@ -83,7 +83,10 @@ func NewDatabase(cfg map[string]string) (*Context, error) {
 		c.Db.LogMode(true)
 		c.Db.LogMode(true)
 	}
 	}
 
 
-	c.flush, _ = strconv.ParseBool(cfg["flush"])
+	c.flush, err = strconv.ParseBool(cfg["flush"])
+	if err != nil {
+		return nil, fmt.Errorf("failed to parse 'flush' value %s : %s", cfg["flush"], err)
+	}
 	// Migrate the schema
 	// Migrate the schema
 	c.Db.AutoMigrate(&types.EventSequence{}, &types.SignalOccurence{}, &types.BanApplication{})
 	c.Db.AutoMigrate(&types.EventSequence{}, &types.SignalOccurence{}, &types.BanApplication{})
 	c.Db.Model(&types.SignalOccurence{}).Related(&types.EventSequence{})
 	c.Db.Model(&types.SignalOccurence{}).Related(&types.EventSequence{})