(app *App)
| 845 | } |
| 846 | |
| 847 | func connectToDatabase(app *App) { |
| 848 | log.Info("Connecting to %s database...", app.cfg.Database.Type) |
| 849 | |
| 850 | var db *sql.DB |
| 851 | var err error |
| 852 | if app.cfg.Database.Type == driverMySQL { |
| 853 | db, err = sql.Open(app.cfg.Database.Type, fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=true&loc=%s&tls=%t", app.cfg.Database.User, app.cfg.Database.Password, app.cfg.Database.Host, app.cfg.Database.Port, app.cfg.Database.Database, url.QueryEscape(time.Local.String()), app.cfg.Database.TLS)) |
| 854 | db.SetMaxOpenConns(50) |
| 855 | } else if app.cfg.Database.Type == driverSQLite { |
| 856 | if !SQLiteEnabled { |
| 857 | log.Error("Invalid database type '%s'. Binary wasn't compiled with SQLite3 support.", app.cfg.Database.Type) |
| 858 | os.Exit(1) |
| 859 | } |
| 860 | if app.cfg.Database.FileName == "" { |
| 861 | log.Error("SQLite database filename value in config.ini is empty.") |
| 862 | os.Exit(1) |
| 863 | } |
| 864 | db, err = sql.Open("sqlite3_with_regex", app.cfg.Database.FileName+"?parseTime=true&cached=shared") |
| 865 | db.SetMaxOpenConns(2) |
| 866 | } else { |
| 867 | log.Error("Invalid database type '%s'. Only 'mysql' and 'sqlite3' are supported right now.", app.cfg.Database.Type) |
| 868 | os.Exit(1) |
| 869 | } |
| 870 | if err != nil { |
| 871 | log.Error("%s", err) |
| 872 | os.Exit(1) |
| 873 | } |
| 874 | app.db = &datastore{DB: db, driverName: app.cfg.Database.Type} |
| 875 | } |
| 876 | |
| 877 | func shutdown(app *App) { |
| 878 | log.Info("Closing database connection...") |
no test coverage detected