Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions pkg/postgres/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math"
"net"
"net/url"
"strings"
"time"
Expand Down Expand Up @@ -58,12 +59,10 @@ func New(cfg config.Postgres, appName string, opts ...Option) *Controller {
l.Logger.Panic().Err(err).Msg("Unsupported SSL mode given")
}

//nolint:nosprintfhostport // False positive, this isn't a regular hostname:port syntax here
dbURL := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s&application_name=%s",
dbURL := fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s&application_name=%s",
cfg.Username,
url.QueryEscape(cfg.Password),
cfg.Hostname,
cfg.Port,
net.JoinHostPort(cfg.Hostname, cfg.Port),
cfg.DBName,
cfg.TLS,
appName,
Expand Down Expand Up @@ -160,12 +159,10 @@ func (c *Controller) Connect(ctx context.Context) error {

// NewMigrationConnection opens a new connection for database migrations
func NewMigrationConnection(cfg config.Postgres) (*sql.DB, error) {
//nolint:nosprintfhostport // False positive, cannot use net.JoinHostPort() here
psqlConfig := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s&application_name=%s",
psqlConfig := fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s&application_name=%s",
cfg.Username,
url.QueryEscape(cfg.Password),
cfg.Hostname,
cfg.Port,
net.JoinHostPort(cfg.Hostname, cfg.Port),
cfg.DBName,
cfg.TLS,
"example-gin migrations",
Expand Down