-
Notifications
You must be signed in to change notification settings - Fork 14
/
postgres.go
46 lines (37 loc) · 827 Bytes
/
postgres.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package pgcommands
import (
"fmt"
)
type Postgres struct {
// DB Host (e.g. 127.0.0.1)
Host string
// DB Port (e.g. 5432)
Port int
// DB Name
DB string
// Connection Username
Username string
// Connection Password
Password string
// Connection Password ENV format PGPASSWORD=
EnvPassword string
}
func (x *Postgres) Parse() []string {
var options []string
if x.DB != "" {
options = append(options, fmt.Sprintf(`--dbname=%v`, x.DB))
}
if x.Host != "" {
options = append(options, fmt.Sprintf(`--host=%v`, x.Host))
}
if x.Port != 0 {
options = append(options, fmt.Sprintf(`--port=%v`, x.Port))
}
if x.Username != "" {
options = append(options, fmt.Sprintf(`--username=%v`, x.Username))
}
if x.Password != "" {
x.EnvPassword = fmt.Sprintf(`PGPASSWORD=%v`, x.Password)
}
return options
}