You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: main.go
+56-63Lines changed: 56 additions & 63 deletions
Original file line number
Diff line number
Diff line change
@@ -20,11 +20,12 @@ import (
20
20
)
21
21
22
22
var (
23
-
config*Config
24
-
filePathstring
25
-
date time.Time
26
-
baseCommandstring
27
-
containerIdstring
23
+
config*Config
24
+
filePathstring
25
+
date time.Time
26
+
baseCommandstring
27
+
containerIdstring
28
+
allDatabasesbool
28
29
)
29
30
30
31
typeConfigstruct {
@@ -39,6 +40,8 @@ type Config struct {
39
40
Namestring`yaml:"name"`
40
41
Usernamestring`yaml:"username"`
41
42
Passwordstring`yaml:"password"`
43
+
Hoststring`yaml:"host"`
44
+
Portint`yaml:"port"`
42
45
} `yaml:"database"`
43
46
}
44
47
@@ -47,23 +50,7 @@ type PutRequest struct {
47
50
Contentstring`json:"content"`
48
51
}
49
52
50
-
funcinit() {
51
-
date=time.Now()
52
-
53
-
varuseHelpbool
54
-
flag.BoolVar(&useHelp, "help", false, "Show this help menu.")
55
-
56
-
flag.StringVar(&filePath, "config", "./config.yml", "Select where is located config file.")
57
-
58
-
flag.StringVar(&containerId, "container", "", "Specific the ID (or name) of the container in which the instance of the database is running, this will avoid the requirement that the command is executed by the postgre user.")
59
-
60
-
flag.Parse()
61
-
62
-
ifuseHelp {
63
-
flag.PrintDefaults()
64
-
os.Exit(0)
65
-
}
66
-
53
+
func (c*Config) init() {
67
54
file, err:=filepath.Abs(filePath)
68
55
iferr!=nil {
69
56
log.Fatal(err)
@@ -80,12 +67,31 @@ func init() {
80
67
}
81
68
82
69
ifconfig.Database.Name=="" {
70
+
if!allDatabases {
71
+
log.Fatalf("database name not defined on %s", file)
72
+
}
83
73
config.Database.Name="all"
84
74
baseCommand="pg_dumpall"
85
75
} else {
86
76
baseCommand="pg_dump"
87
77
}
88
78
79
+
ifconfig.Database.Host=="" {
80
+
config.Database.Host="127.0.0.1"
81
+
}
82
+
83
+
ifconfig.Database.Port==0 {
84
+
config.Database.Port=5432
85
+
}
86
+
87
+
ifconfig.Database.Username=="" {
88
+
log.Fatalf("database username not defined on %s", file)
89
+
}
90
+
91
+
ifconfig.Database.Password=="" {
92
+
log.Fatalf("database password not defined on %s", file)
93
+
}
94
+
89
95
ifconfig.S3.Region=="" {
90
96
log.Fatalf("s3 region not defined on %s", file)
91
97
}
@@ -103,6 +109,27 @@ func init() {
103
109
}
104
110
}
105
111
112
+
funcinit() {
113
+
date=time.Now()
114
+
115
+
varuseHelpbool
116
+
flag.BoolVar(&useHelp, "help", false, "Show this help menu.")
117
+
flag.BoolVar(&allDatabases, "all", false, "If defined will be dumped all the databases (pg_dumpall instead of pg_dump)")
118
+
119
+
flag.StringVar(&filePath, "config", "./config.yml", "Select where is located config file.")
120
+
121
+
flag.StringVar(&containerId, "container", "", "Specific the ID (or name) of the container in which the instance of the database is running, this will avoid the requirement that the command is executed by the postgre user.")
0 commit comments