-
Notifications
You must be signed in to change notification settings - Fork 45
/
command.go
57 lines (46 loc) · 979 Bytes
/
command.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
47
48
49
50
51
52
53
54
55
56
57
package command
import "os"
// Options is a struct that stores the provided commands by the user.
type Options struct {
Driver string
URL string
Host string
Port string
User string
Pass string
DBName string
SSL string
// PostgreSQL only.
Schema string
Limit uint
Socket string
}
// SetDefault returns a Options struct and fills the empty
// values with environment variables if any.
func SetDefault(opts Options) Options {
if opts.URL == "" {
opts.URL = os.Getenv("DATABASE_URL")
}
if opts.Driver == "" {
opts.Driver = os.Getenv("DB_DRIVER")
}
if opts.Host == "" {
opts.Host = os.Getenv("DB_HOST")
}
if opts.User == "" {
opts.User = os.Getenv("DB_USER")
}
if opts.Pass == "" {
opts.Pass = os.Getenv("DB_PASSWORD")
}
if opts.DBName == "" {
opts.DBName = os.Getenv("DB_NAME")
}
if opts.Port == "" {
opts.Port = os.Getenv("DB_PORT")
}
if opts.Schema == "" {
opts.Schema = os.Getenv("DB_SCHEMA")
}
return opts
}