Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 90331d1

Browse files
committed
add a copy of postgresDsn that's exported
Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
1 parent b7a7fb6 commit 90331d1

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

database/postgres.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ func getPostgresDsn(ctx context.Context, pgConfig PostgresConfig) string {
4949
pgConfig.Host, pgConfig.Port, pgConfig.DbName, pgConfig.User, password, pgConfig.ExtraOptions)
5050
}
5151

52+
func PostgresDsn(ctx context.Context, pgConfig PostgresConfig) string {
53+
password := resolvePassword(ctx, pgConfig.Password, pgConfig.PasswordPath)
54+
if len(password) == 0 {
55+
// The password-less case is included for development environments.
56+
return fmt.Sprintf("host=%s port=%d dbname=%s user=%s sslmode=disable",
57+
pgConfig.Host, pgConfig.Port, pgConfig.DbName, pgConfig.User)
58+
}
59+
return fmt.Sprintf("host=%s port=%d dbname=%s user=%s password=%s %s",
60+
pgConfig.Host, pgConfig.Port, pgConfig.DbName, pgConfig.User, password, pgConfig.ExtraOptions)
61+
}
62+
5263
// CreatePostgresDbIfNotExists creates DB if it doesn't exist for the passed in config
5364
func CreatePostgresDbIfNotExists(ctx context.Context, gormConfig *gorm.Config, pgConfig PostgresConfig) (*gorm.DB, error) {
5465
dialector := postgres.Open(getPostgresDsn(ctx, pgConfig))

0 commit comments

Comments
 (0)