Skip to content

Commit 54faf5d

Browse files
committed
Code cleanup
1 parent 7959721 commit 54faf5d

15 files changed

+142
-125
lines changed

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func main() {
8989
defer func() {
9090
if r := recover(); r != nil {
9191
fmt.Println()
92+
fmt.Println("PANIC CATCHED")
9293

9394
message := fmt.Sprintf("%v", r)
9495

sync/config.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,83 +8,83 @@ import (
88
var waitGroup sync.WaitGroup
99

1010
type Filter struct {
11-
Exclude []string
11+
Exclude []string `yaml:"exclude"`
1212
excludeRegexp []*regexp.Regexp
13-
Include []string
13+
Include []string `yaml:"include"`
1414
includeRegexp []*regexp.Regexp
1515
}
1616

1717
type Filesystem struct {
18-
Path string
19-
Local string
20-
Filter Filter
21-
Connection YamlCommandBuilderConnection
18+
Path string `yaml:"path"`
19+
Local string `yaml:"local"`
20+
Filter Filter `yaml:"filter"`
21+
Connection *YamlCommandBuilderConnection `yaml:"connection"`
2222
Options struct {
2323
GenerateStubs bool `yaml:"generate-stubs"`
24-
}
24+
} `yaml:"options"`
2525
}
2626

2727
type DatabaseOptions struct {
2828
ClearDatabase bool `yaml:"clear-database"`
29-
Mysqldump string
30-
Mysql string
31-
Pgdump string
32-
Psql string
29+
Mysqldump string `yaml:"mysqldump"`
30+
Mysql string `yaml:"mysql"`
31+
Pgdump string `yaml:"pgdump"`
32+
Psql string `yaml:"psql"`
3333
}
3434

3535
type EnvironmentVar struct {
36-
Name string
37-
Value string
36+
Name string `yaml:"name"`
37+
Value string `yaml:"value"`
3838
}
3939

4040
type Database struct {
41-
Type string
42-
Schema string
43-
Hostname string
44-
Port string
45-
User string
46-
Password string
41+
Type string `yaml:"type"`
42+
Schema string `yaml:"schema"`
43+
Hostname string `yaml:"hostname"`
44+
Port string `yaml:"port"`
45+
User string `yaml:"user"`
46+
Password string `yaml:"password"`
4747

48-
Filter Filter
49-
Connection YamlCommandBuilderConnection
48+
Filter Filter `yaml:"filter"`
49+
Connection *YamlCommandBuilderConnection `yaml:"connection"`
50+
Options DatabaseOptions `yaml:"options"`
5051

5152
Local struct {
52-
Type string
53-
Schema string
54-
Hostname string
55-
Port string
56-
User string
57-
Password string
53+
Type string `yaml:"type"`
54+
Schema string `yaml:"schema"`
55+
Hostname string `yaml:"hostname"`
56+
Port string `yaml:"port"`
57+
User string `yaml:"user"`
58+
Password string `yaml:"password"`
5859

59-
Connection YamlCommandBuilderConnection
60-
Options DatabaseOptions
61-
}
62-
Options DatabaseOptions
60+
Connection *YamlCommandBuilderConnection `yaml:"connection"`
61+
Options DatabaseOptions `yaml:"options"`
62+
} `yaml:"local"`
6363

6464
// local cache
6565
cacheRemoteTableList []string
6666
cacheLocalTableList []string
6767
}
6868

6969
type Execution struct {
70-
Type string
71-
Command YamlStringArray
72-
Workdir string
73-
Environment []EnvironmentVar
70+
Type string `yaml:"type"`
71+
Command YamlStringArray `yaml:"command"`
72+
Workdir string `yaml:"workdir"`
73+
Environment []EnvironmentVar `yaml:"environment"`
7474
Options struct {
75-
}
75+
} `yaml:"options"`
7676
}
7777

7878
type Server struct {
79-
Path string
80-
Connection YamlCommandBuilderConnection
81-
Filesystem []Filesystem
82-
Database []Database
79+
Path string `yaml:"path"`
80+
Connection *YamlCommandBuilderConnection `yaml:"connection"`
81+
Filesystem []Filesystem `yaml:"filesystem"`
82+
Database []Database `yaml:"database"`
8383
ExecStartup []Execution `yaml:"exec-startup"`
8484
ExecFinish []Execution `yaml:"exec-finish"`
8585
}
8686

8787
type SyncConfig struct {
88-
Sync map[string]Server
89-
Deploy map[string]Server
88+
Sync map[string]Server `yaml:"sync"`
89+
Deploy map[string]Server `yaml:"deploy"`
9090
}

sync/configparser.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ databaseExcludeTYPO3:
2424
---
2525
`
2626

27-
28-
29-
func NewConfigParser(file string) *SyncConfig {
30-
config := SyncConfig{}
31-
27+
func NewConfigParser(file string) (config *SyncConfig) {
3228
ymlData, err := ioutil.ReadFile(file)
3329
if err != nil {
3430
Logger.FatalErrorExit(1, err)
@@ -41,7 +37,7 @@ func NewConfigParser(file string) *SyncConfig {
4137
Logger.FatalErrorExit(1, err)
4238
}
4339

44-
return &config
40+
return
4541
}
4642

4743
func (config *SyncConfig) GetSyncServer(serverName string) (Server, error) {
@@ -60,42 +56,38 @@ func (config *SyncConfig) GetDeployServer(serverName string) (Server, error) {
6056
}
6157
}
6258

63-
func (config *SyncConfig) GetServerList(confType string) []string {
64-
ret := []string{}
65-
59+
func (config *SyncConfig) GetServerList(confType string) (list []string) {
6660
switch confType {
6761
case "sync":
6862
for key := range config.Sync {
69-
ret = append(ret, key)
63+
list = append(list, key)
7064
}
7165
case "deploy":
7266
for key := range config.Deploy {
73-
ret = append(ret, key)
67+
list = append(list, key)
7468
}
7569
}
7670

77-
return ret
71+
return
7872
}
7973

8074
// List all possible server configurations
81-
func (config *SyncConfig) ListServer() map[string][]string {
82-
ret := map[string][]string{}
83-
75+
func (config *SyncConfig) ListServer() (list map[string][]string) {
8476
if len(config.Sync) > 0 {
85-
ret["Sync"] = make([]string, len(config.Sync)-1)
77+
list["Sync"] = make([]string, len(config.Sync)-1)
8678
for key := range config.Sync {
87-
ret["Sync"] = append(ret["Sync"], key)
79+
list["Sync"] = append(list["Sync"], key)
8880
}
8981
}
9082

9183
if len(config.Deploy) > 0 {
92-
ret["Deploy"] = make([]string, len(config.Deploy)-1)
84+
list["Deploy"] = make([]string, len(config.Deploy)-1)
9385
for key := range config.Deploy {
94-
ret["Deploy"] = append(ret["Deploy"], key)
86+
list["Deploy"] = append(list["Deploy"], key)
9587
}
9688
}
9789

98-
return ret
90+
return
9991
}
10092

10193
// Show all possible server configurations

sync/database.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@ package sync
33
import (
44
"fmt"
55
"strings"
6-
"github.com/mohae/deepcopy"
76
)
87

98
func (database *Database) ApplyDefaults(server *Server) {
109
// set default connection if not set
11-
if database.Connection.IsEmpty() {
12-
database.Connection = deepcopy.Copy(server.Connection).(YamlCommandBuilderConnection)
10+
if database.Connection == nil {
11+
*database.Connection = *server.Connection
1312
}
1413
}
1514

16-
func (database *Database) GetType() string {
17-
var dbtype string
18-
15+
func (database *Database) GetType() (dbtype string) {
1916
switch database.Type {
2017
case "mysql":
2118
dbtype = "mysql"

sync/database_mysql.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ func (database *DatabaseMysql) init() {
9999
}
100100
}
101101

102-
func (database *DatabaseMysql) tableFilter(connectionType string) ([]string, []string) {
103-
var exclude []string
104-
var include []string
105-
102+
func (database *DatabaseMysql) tableFilter(connectionType string) (exclude []string, include []string) {
106103
var tableList []string
107104

108105
if connectionType == "local" {

sync/database_mysql_local.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package sync
22

3-
import "github.com/webdevops/go-shell"
3+
import (
4+
"github.com/webdevops/go-shell"
5+
)
46

57
func (database *DatabaseMysql) localMysqldumpCmdBuilder(additionalArgs []string, useFilter bool) []interface{} {
68
var args []string
@@ -12,7 +14,7 @@ func (database *DatabaseMysql) localMysqldumpCmdBuilder(additionalArgs []string,
1214
}
1315

1416
if database.Local.Password != "" {
15-
connection.Environment["MYSQL_PWD"] = database.Local.Password
17+
connection.Environment.Set("MYSQL_PWD", database.Local.Password)
1618
}
1719

1820
if database.Local.Hostname != "" {
@@ -59,7 +61,7 @@ func (database *DatabaseMysql) localMysqlCmdBuilder(args ...string) []interface{
5961
}
6062

6163
if database.Local.Password != "" {
62-
connection.Environment["MYSQL_PWD"] = database.Local.Password
64+
connection.Environment.Set("MYSQL_PWD", database.Local.Password)
6365
}
6466

6567
if database.Local.Hostname != "" {

sync/database_mysql_remote.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (database *DatabaseMysql) remoteMysqldumpCmdBuilder(additionalArgs []string
1515
}
1616

1717
if database.Password != "" {
18-
connection.Environment["MYSQL_PWD"] = database.Password
18+
connection.Environment.Set("MYSQL_PWD", database.Password)
1919
}
2020

2121
if database.Hostname != "" {
@@ -67,7 +67,7 @@ func (database *DatabaseMysql) remoteMysqlCmdBuilder(args ...string) []interface
6767
}
6868

6969
if database.Password != "" {
70-
connection.Environment["MYSQL_PWD"] = database.Password
70+
connection.Environment.Set("MYSQL_PWD", database.Password)
7171
}
7272

7373
if database.Hostname != "" {
@@ -101,7 +101,7 @@ func (database *DatabaseMysql) remoteMysqlCmdBuilderUncompress(args ...string) [
101101
}
102102

103103
if database.Password != "" {
104-
connection.Environment["MYSQL_PWD"] = database.Password
104+
connection.Environment.Set("MYSQL_PWD", database.Password)
105105
}
106106

107107
if database.Hostname != "" {

sync/database_postgres.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ type DatabasePostgres struct {
1010
Database
1111
}
1212

13-
1413
func (database *DatabasePostgres) init() {
1514
connLocal := database.Local.Connection.GetInstance()
1615
connRemote := database.Connection.GetInstance()
1716

18-
1917
// LOCAL
2018
if connLocal.IsDocker() {
2119
if database.Local.User == "" || database.Local.Schema == "" {
@@ -81,10 +79,7 @@ func (database *DatabasePostgres) init() {
8179
}
8280
}
8381

84-
func (database *DatabasePostgres) tableFilter(connectionType string) ([]string, []string) {
85-
var exclude []string
86-
var include []string
87-
82+
func (database *DatabasePostgres) tableFilter(connectionType string) (exclude []string, include []string) {
8883
var tableList []string
8984

9085
if connectionType == "local" {
@@ -115,7 +110,7 @@ func (database *DatabasePostgres) tableFilter(connectionType string) ([]string,
115110
include = append(include, shell.Quote(fmt.Sprintf("--table=%s", table)))
116111
}
117112

118-
return exclude, include
113+
return
119114
}
120115

121116
func (database *DatabasePostgres) psqlCommandBuilder(direction string, args ...string) []interface{} {

sync/database_postgres_local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func (database *DatabasePostgres) localPgdumpCmdBuilder(additionalArgs []string,
1111
}
1212

1313
if database.Local.Password != "" {
14-
connection.Environment["PGPASSWORD"] = database.Local.Password
14+
connection.Environment.Set("PGPASSWORD", database.Local.Password)
1515
}
1616

1717
if database.Local.Hostname != "" {
@@ -57,7 +57,7 @@ func (database *DatabasePostgres) localPsqlCmdBuilder(args ...string) []interfac
5757
}
5858

5959
if database.Local.Password != "" {
60-
connection.Environment["PGPASSWORD"] = database.Local.Password
60+
connection.Environment.Set("PGPASSWORD", database.Local.Password)
6161
}
6262

6363
if database.Local.Hostname != "" {

sync/database_postgres_remote.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (database *DatabasePostgres) remotePgdumpCmdBuilder(additionalArgs []string
1414
}
1515

1616
if database.Password != "" {
17-
connection.Environment["PGPASSWORD"] = database.Password
17+
connection.Environment.Set("PGPASSWORD", database.Password)
1818
}
1919

2020
if database.Hostname != "" {
@@ -65,7 +65,7 @@ func (database *DatabasePostgres) remotePsqlCmdBuilder(args ...string) []interfa
6565
}
6666

6767
if database.Password != "" {
68-
connection.Environment["PGPASSWORD"] = database.Password
68+
connection.Environment.Set("PGPASSWORD", database.Password)
6969
}
7070

7171
if database.Hostname != "" {
@@ -98,7 +98,7 @@ func (database *DatabasePostgres) remotePsqlCmdBuilderUncompress(args ...string)
9898
}
9999

100100
if database.Password != "" {
101-
connection.Environment["MYSQL_PWD"] = database.Password
101+
connection.Environment.Set("MYSQL_PWD", database.Password)
102102
}
103103

104104
if database.Hostname != "" {

0 commit comments

Comments
 (0)