浏览代码

feat: add config to enable/disable postgres ssl mode

Vivek R 6 年之前
父节点
当前提交
09117426ee
共有 3 个文件被更改,包括 6 次插入4 次删除
  1. 2 1
      config.toml.sample
  2. 2 1
      main.go
  3. 2 2
      queries.go

+ 2 - 1
config.toml.sample

@@ -35,7 +35,7 @@ upload_uri = "/uploads"
 # Maximum concurrent workers that will attempt to send messages
 # Maximum concurrent workers that will attempt to send messages
 # simultaneously. This should depend on the number of CPUs the
 # simultaneously. This should depend on the number of CPUs the
 # machine has and also the number of simultaenous e-mails the
 # machine has and also the number of simultaenous e-mails the
-# mail server will  
+# mail server will
 concurrency = 100
 concurrency = 100
 
 
 # The number of errors (eg: SMTP timeouts while e-mailing) a running
 # The number of errors (eg: SMTP timeouts while e-mailing) a running
@@ -51,6 +51,7 @@ port = 5432
 user = "listmonk"
 user = "listmonk"
 password = ""
 password = ""
 database = "listmonk"
 database = "listmonk"
+ssl_mode = "disable"
 
 
 # TQekh4quVgGc3HQ
 # TQekh4quVgGc3HQ
 
 

+ 2 - 1
main.go

@@ -148,7 +148,8 @@ func main() {
 		viper.GetInt("db.port"),
 		viper.GetInt("db.port"),
 		viper.GetString("db.user"),
 		viper.GetString("db.user"),
 		viper.GetString("db.password"),
 		viper.GetString("db.password"),
-		viper.GetString("db.database"))
+		viper.GetString("db.database"),
+		viper.GetString("db.ssl_mode"))
 	if err != nil {
 	if err != nil {
 		logger.Fatalf("error connecting to DB: %v", err)
 		logger.Fatalf("error connecting to DB: %v", err)
 	}
 	}

+ 2 - 2
queries.go

@@ -79,9 +79,9 @@ type Queries struct {
 }
 }
 
 
 // connectDB initializes a database connection.
 // connectDB initializes a database connection.
-func connectDB(host string, port int, user, pwd, dbName string) (*sqlx.DB, error) {
+func connectDB(host string, port int, user, pwd, dbName string, sslMode string) (*sqlx.DB, error) {
 	db, err := sqlx.Connect("postgres",
 	db, err := sqlx.Connect("postgres",
-		fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s", host, port, user, pwd, dbName))
+		fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", host, port, user, pwd, dbName, sslMode))
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}