mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(database): postgres set ssl mode (#1245)
* feat(database): postgres set ssl mode * feat(database): postgres set extra params
This commit is contained in:
parent
8c89481d88
commit
73e76c4214
3 changed files with 43 additions and 36 deletions
|
@ -182,23 +182,25 @@ func New(configPath string, version string) *AppConfig {
|
||||||
|
|
||||||
func (c *AppConfig) defaults() {
|
func (c *AppConfig) defaults() {
|
||||||
c.Config = &domain.Config{
|
c.Config = &domain.Config{
|
||||||
Version: "dev",
|
Version: "dev",
|
||||||
Host: "localhost",
|
Host: "localhost",
|
||||||
Port: 7474,
|
Port: 7474,
|
||||||
LogLevel: "TRACE",
|
LogLevel: "TRACE",
|
||||||
LogPath: "",
|
LogPath: "",
|
||||||
LogMaxSize: 50,
|
LogMaxSize: 50,
|
||||||
LogMaxBackups: 3,
|
LogMaxBackups: 3,
|
||||||
BaseURL: "/",
|
BaseURL: "/",
|
||||||
SessionSecret: api.GenerateSecureToken(16),
|
SessionSecret: api.GenerateSecureToken(16),
|
||||||
CustomDefinitions: "",
|
CustomDefinitions: "",
|
||||||
CheckForUpdates: true,
|
CheckForUpdates: true,
|
||||||
DatabaseType: "sqlite",
|
DatabaseType: "sqlite",
|
||||||
PostgresHost: "",
|
PostgresHost: "",
|
||||||
PostgresPort: 0,
|
PostgresPort: 0,
|
||||||
PostgresDatabase: "",
|
PostgresDatabase: "",
|
||||||
PostgresUser: "",
|
PostgresUser: "",
|
||||||
PostgresPass: "",
|
PostgresPass: "",
|
||||||
|
PostgresSSLMode: "disable",
|
||||||
|
PostgresExtraParams: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,10 @@ func NewDB(cfg *domain.Config, log logger.Logger) (*DB, error) {
|
||||||
if cfg.PostgresHost == "" || cfg.PostgresPort == 0 || cfg.PostgresDatabase == "" {
|
if cfg.PostgresHost == "" || cfg.PostgresPort == 0 || cfg.PostgresDatabase == "" {
|
||||||
return nil, errors.New("postgres: bad variables")
|
return nil, errors.New("postgres: bad variables")
|
||||||
}
|
}
|
||||||
db.DSN = fmt.Sprintf("postgres://%v:%v@%v:%d/%v?sslmode=disable", cfg.PostgresUser, cfg.PostgresPass, cfg.PostgresHost, cfg.PostgresPort, cfg.PostgresDatabase)
|
db.DSN = fmt.Sprintf("postgres://%v:%v@%v:%d/%v?sslmode=%v", cfg.PostgresUser, cfg.PostgresPass, cfg.PostgresHost, cfg.PostgresPort, cfg.PostgresDatabase, cfg.PostgresSSLMode)
|
||||||
|
if cfg.PostgresExtraParams != "" {
|
||||||
|
db.DSN = fmt.Sprintf("%s&%s", db.DSN, cfg.PostgresExtraParams)
|
||||||
|
}
|
||||||
db.Driver = "postgres"
|
db.Driver = "postgres"
|
||||||
databaseDriver = "postgres"
|
databaseDriver = "postgres"
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -4,24 +4,26 @@
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Version string
|
Version string
|
||||||
ConfigPath string
|
ConfigPath string
|
||||||
Host string `toml:"host"`
|
Host string `toml:"host"`
|
||||||
Port int `toml:"port"`
|
Port int `toml:"port"`
|
||||||
LogLevel string `toml:"logLevel"`
|
LogLevel string `toml:"logLevel"`
|
||||||
LogPath string `toml:"logPath"`
|
LogPath string `toml:"logPath"`
|
||||||
LogMaxSize int `toml:"logMaxSize"`
|
LogMaxSize int `toml:"logMaxSize"`
|
||||||
LogMaxBackups int `toml:"logMaxBackups"`
|
LogMaxBackups int `toml:"logMaxBackups"`
|
||||||
BaseURL string `toml:"baseUrl"`
|
BaseURL string `toml:"baseUrl"`
|
||||||
SessionSecret string `toml:"sessionSecret"`
|
SessionSecret string `toml:"sessionSecret"`
|
||||||
CustomDefinitions string `toml:"customDefinitions"`
|
CustomDefinitions string `toml:"customDefinitions"`
|
||||||
CheckForUpdates bool `toml:"checkForUpdates"`
|
CheckForUpdates bool `toml:"checkForUpdates"`
|
||||||
DatabaseType string `toml:"databaseType"`
|
DatabaseType string `toml:"databaseType"`
|
||||||
PostgresHost string `toml:"postgresHost"`
|
PostgresHost string `toml:"postgresHost"`
|
||||||
PostgresPort int `toml:"postgresPort"`
|
PostgresPort int `toml:"postgresPort"`
|
||||||
PostgresDatabase string `toml:"postgresDatabase"`
|
PostgresDatabase string `toml:"postgresDatabase"`
|
||||||
PostgresUser string `toml:"postgresUser"`
|
PostgresUser string `toml:"postgresUser"`
|
||||||
PostgresPass string `toml:"postgresPass"`
|
PostgresPass string `toml:"postgresPass"`
|
||||||
|
PostgresSSLMode string `toml:"postgresSSLMode"`
|
||||||
|
PostgresExtraParams string `toml:"PostgresExtraParams"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigUpdate struct {
|
type ConfigUpdate struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue