| 173 | } |
| 174 | |
| 175 | func (server *Server) getDatabaseConfig() (string, string, db.InitDBParams) { |
| 176 | config := util.GetConfig() |
| 177 | databaseType := config.GetString("database/type", "sqlite3") |
| 178 | if databaseType == "json" || databaseType == "yaml" { |
| 179 | log.Fatal("json or yaml isn't supported as main db backend") |
| 180 | } |
| 181 | databaseConnection := config.GetString("database/connection", "") |
| 182 | if databaseConnection == "" { |
| 183 | log.Fatal("no database connection specified in the configuration file.") |
| 184 | } |
| 185 | databaseDropOnCreate := config.GetBool("database/drop_on_create", false) |
| 186 | databaseCascade := config.GetBool("database/cascade_delete", false) |
| 187 | databaseAutoMigrate := config.GetBool("database/auto_migrate", true) |
| 188 | return databaseType, databaseConnection, db.InitDBParams{ |
| 189 | DropOnCreate: databaseDropOnCreate, |
| 190 | Cascade: databaseCascade, |
| 191 | AutoMigrate: databaseAutoMigrate, |
| 192 | AllowEmpty: false, |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | //NewServer returns new GohanAPIServer |
| 197 | func NewServer(configFile string) (*Server, error) { |