Skip to content

Commit

Permalink
backend/postgres: Allow to pass application_name in the DSN
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisMontagne committed Jan 9, 2024
1 parent 52d9b8c commit 7878a8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions backend/postgres/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Config struct {
User string
Password string

ApplicationName string

SSLMode SSLMode
SSLSNI bool

Expand Down Expand Up @@ -151,6 +153,10 @@ func (c *Config) DSN() (string, error) {
return "", err
}

if c.ApplicationName != "" {
q.Add("application_name", c.ApplicationName)
}

u := url.URL{
Scheme: "postgres",
User: c.userInfo(),
Expand Down
4 changes: 2 additions & 2 deletions backend/postgres/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestDSN(t *testing.T) {
dsn: "postgres://localhost:5432/foobar?sslmode=verify-full&sslsni=1",
},
{
c: &Config{DBName: "foobar", CACertFile: "foobar"},
dsn: "postgres://localhost:5432/foobar?sslmode=verify-ca&sslrootcert=foobar&sslsni=0",
c: &Config{DBName: "foobar", CACertFile: "foobar", ApplicationName: "buz"},
dsn: "postgres://localhost:5432/foobar?application_name=buz&sslmode=verify-ca&sslrootcert=foobar&sslsni=0",
},
} {
dsn, err := tt.c.DSN()
Expand Down

0 comments on commit 7878a8d

Please sign in to comment.