forked from bradw2k/form5500-data-sets-import
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flags.go
36 lines (27 loc) · 909 Bytes
/
flags.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
package utils
import (
"fmt"
"log"
)
// Form5500Flags store cli flags to a struct
type Form5500Flags struct {
Connection string
Years []string
Section string
}
// SetConnection Set attributes from cli inputs
func (f *Form5500Flags) SetConnection(host string, port string, db string, sslmode string, user string, password string) {
if db == "" {
log.Fatal("-db flag is required")
}
var connectionPartial string
if user != "" && password != "" {
connectionPartial = fmt.Sprintf("user=%s password=%s ", user, password)
} else {
connectionPartial = ""
}
if !(sslmode == "require" || sslmode == "verify-full" || sslmode == "verify-ca" || sslmode == "disable") {
log.Fatal("-ssl only supports disable (default), 'verify-full', 'verify-ca', 'require'")
}
f.Connection = fmt.Sprintf("host=%s port=%s dbname=%s sslmode=%s %s", host, port, db, sslmode, connectionPartial)
}