Skip to content

Commit 44548f7

Browse files
author
hidu
committed
clean deps
1 parent 924202c commit 44548f7

File tree

11 files changed

+63
-73
lines changed

11 files changed

+63
-73
lines changed

go.mod

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@ go 1.25.1
44

55
require (
66
github.com/elliotchance/orderedmap v1.8.0
7-
github.com/fatih/color v1.18.0
87
github.com/go-sql-driver/mysql v1.9.3
9-
github.com/stretchr/testify v1.11.1
10-
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
8+
github.com/xanygo/anygo v0.0.0-20251026013910-9151a851035d
119
)
1210

1311
require (
1412
filippo.io/edwards25519 v1.1.0 // indirect
15-
github.com/davecgh/go-spew v1.1.1 // indirect
16-
github.com/mattn/go-colorable v0.1.13 // indirect
17-
github.com/mattn/go-isatty v0.0.20 // indirect
18-
github.com/pmezard/go-difflib v1.0.0 // indirect
19-
golang.org/x/sys v0.25.0 // indirect
20-
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
21-
gopkg.in/yaml.v3 v3.0.1 // indirect
13+
github.com/stretchr/testify v1.11.1 // indirect
2214
)

go.sum

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,17 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/elliotchance/orderedmap v1.8.0 h1:TrOREecvh3JbS+NCgwposXG5ZTFHtEsQiCGOhPElnMw=
77
github.com/elliotchance/orderedmap v1.8.0/go.mod h1:wsDwEaX5jEoyhbs7x93zk2H/qv0zwuhg4inXhDkYqys=
8-
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
9-
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
108
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
119
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
12-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
13-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
14-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
15-
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
16-
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
1710
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1811
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1912
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2013
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
2114
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
2215
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
23-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
24-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
25-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
26-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
27-
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
28-
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
29-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
16+
github.com/xanygo/anygo v0.0.0-20251026013910-9151a851035d h1:EqXtmiXp6lnP12nAt7tlLpU///4pvNvAyfe6IhT1dMg=
17+
github.com/xanygo/anygo v0.0.0-20251026013910-9151a851035d/go.mod h1:Z2c+FB/85TK4MnI6lIwGFAH0Q6/kQ3t6dGK8+IZAUxk=
3018
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
31-
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
32-
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
3319
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3420
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3521
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/charset_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
package internal
66

77
import (
8+
"fmt"
89
"testing"
910

10-
"github.com/stretchr/testify/require"
11+
"github.com/xanygo/anygo/xt"
1112
)
1213

1314
func TestFieldInfo_CharsetCollationComparison(t *testing.T) {
@@ -29,8 +30,8 @@ func TestFieldInfo_CharsetCollationComparison(t *testing.T) {
2930
}
3031

3132
// These should be considered equal
32-
require.True(t, sourceField.Equals(destField), "Fields with implicit and explicit charset/collation should be equal")
33-
require.True(t, destField.Equals(sourceField), "Fields with explicit and implicit charset/collation should be equal")
33+
xt.True(t, sourceField.Equals(destField))
34+
xt.True(t, destField.Equals(sourceField))
3435
}
3536

3637
func TestFieldInfo_DifferentCharsetCollation(t *testing.T) {
@@ -52,8 +53,8 @@ func TestFieldInfo_DifferentCharsetCollation(t *testing.T) {
5253
}
5354

5455
// These should be considered different
55-
require.False(t, sourceField.Equals(destField), "Fields with different charset should be different")
56-
require.False(t, destField.Equals(sourceField), "Fields with different charset should be different")
56+
xt.False(t, sourceField.Equals(destField))
57+
xt.False(t, destField.Equals(sourceField))
5758
}
5859

5960
func TestFieldInfo_WithTimestamps(t *testing.T) {
@@ -130,11 +131,11 @@ func TestFieldInfo_WithTimestamps(t *testing.T) {
130131

131132
// All fields should be considered equal
132133
for fieldName, sourceField := range sourceFields {
133-
destField := destFields[fieldName]
134-
require.True(t, sourceField.Equals(destField),
135-
"Field %s should be equal between source and dest", fieldName)
136-
require.True(t, destField.Equals(sourceField),
137-
"Field %s should be equal between dest and source", fieldName)
134+
t.Run(fmt.Sprintf("field_%s", fieldName), func(t *testing.T) {
135+
destField := destFields[fieldName]
136+
xt.True(t, sourceField.Equals(destField))
137+
xt.True(t, destField.Equals(sourceField))
138+
})
138139
}
139140
}
140141

@@ -215,11 +216,11 @@ func TestFieldInfo_DefaultCharsets(t *testing.T) {
215216
}
216217

217218
if tc.shouldEqual {
218-
require.True(t, field1.Equals(field2), "Fields should be equal: %s", tc.name)
219-
require.True(t, field2.Equals(field1), "Fields should be equal (reverse): %s", tc.name)
219+
xt.True(t, field1.Equals(field2))
220+
xt.True(t, field2.Equals(field1))
220221
} else {
221-
require.False(t, field1.Equals(field2), "Fields should be different: %s", tc.name)
222-
require.False(t, field2.Equals(field1), "Fields should be different (reverse): %s", tc.name)
222+
xt.False(t, field1.Equals(field2))
223+
xt.False(t, field2.Equals(field1))
223224
}
224225
})
225226
}

internal/db.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/fatih/color"
1110
_ "github.com/go-sql-driver/mysql" // mysql driver
11+
"github.com/xanygo/anygo/cli/xcolor"
1212
)
1313

1414
// FieldInfo represents detailed field information from INFORMATION_SCHEMA.COLUMNS
@@ -331,8 +331,8 @@ func (db *MyDb) Query(query string, args ...any) (rows *sql.Rows, err error) {
331331
txt := fmt.Sprintf("[%-6s: %s] [Query] Start SQL=%s Args=%s\n",
332332
db.dbType,
333333
db.dbName,
334-
color.GreenString("%s", strings.TrimSpace(query)),
335-
color.GreenString("%v", args),
334+
xcolor.GreenString("%s", strings.TrimSpace(query)),
335+
xcolor.GreenString("%v", args),
336336
)
337337
log.Output(2, txt)
338338
start := time.Now()

internal/email.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package internal
22

33
import (
4+
"context"
45
"log"
6+
"net"
57
"strconv"
68
"strings"
9+
"time"
710

8-
"gopkg.in/gomail.v2"
11+
"github.com/xanygo/anygo/xnet/xsmtp"
912
)
1013

1114
// EmailStruct email conf info
@@ -45,9 +48,9 @@ func (m *EmailStruct) SendMail(title string, body string) {
4548
log.Println("smtp_host, from,to is empty")
4649
return
4750
}
48-
addrInfo := strings.Split(m.SMTPHost, ":")
49-
if len(addrInfo) != 2 {
50-
log.Println("smtp_host wrong, eg: host_name:25")
51+
host, port, err := net.SplitHostPort(m.SMTPHost)
52+
if err != nil {
53+
log.Println("invalid SMTPHost:", m.SMTPHost)
5154
return
5255
}
5356
var sendTo []string
@@ -64,17 +67,24 @@ func (m *EmailStruct) SendMail(title string, body string) {
6467
}
6568

6669
body = mailBody(body)
70+
portInt, _ := strconv.Atoi(port)
6771

68-
a := gomail.NewMessage()
69-
a.SetHeader("From", m.From)
70-
a.SetHeader("To", sendTo...) // 发送给多个用户
71-
a.SetHeader("Subject", title) // 设置邮件主题
72-
a.SetBody("text/html", body) // 设置邮件正文
73-
port, _ := strconv.Atoi(addrInfo[1])
72+
cfg := &xsmtp.Config{
73+
Host: host,
74+
Port: portInt,
75+
Username: m.From,
76+
Password: m.Password,
77+
}
78+
mail := &xsmtp.Mail{
79+
To: sendTo,
80+
Subject: title,
81+
Content: body,
82+
}
7483

75-
d := gomail.NewDialer(addrInfo[0], port, m.From, m.Password)
84+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
85+
defer cancel()
7686

77-
err := d.DialAndSend(a)
87+
err = cfg.Send(ctx, mail)
7888
if err == nil {
7989
log.Println("send mail success")
8090
} else {

internal/execute.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"log"
1010
"strings"
1111

12-
"github.com/fatih/color"
12+
"github.com/xanygo/anygo/cli/xcolor"
1313
)
1414

1515
func Execute(cfg *Config) {
@@ -26,25 +26,25 @@ func Execute(cfg *Config) {
2626
changedTables := make(map[string][]*TableAlterData)
2727

2828
for _, table := range allTables {
29-
color.Green("start checking table %q ...", table)
29+
xcolor.Green("start checking table %q ...", table)
3030
if !cfg.CheckMatchTables(table) {
31-
color.Cyan("table %q skipped by not match", table)
31+
xcolor.Cyan("table %q skipped by not match", table)
3232
continue
3333
}
3434

3535
if cfg.CheckMatchIgnoreTables(table) {
36-
color.Cyan("table %q skipped by ignore", table)
36+
xcolor.Cyan("table %q skipped by ignore", table)
3737
continue
3838
}
3939

4040
sd := sc.getAlterDataByTable(table, cfg)
4141

4242
switch sd.Type {
4343
case alterTypeNo:
44-
color.Yellow("table %q not changed", table)
44+
xcolor.Yellow("table %q not changed", table)
4545
continue
4646
case alterTypeDropTable:
47-
color.Yellow("table %q skipped, only exists in destination's database", table)
47+
xcolor.Yellow("table %q skipped, only exists in destination's database", table)
4848
continue
4949
default:
5050
}

internal/field_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package internal
77
import (
88
"testing"
99

10-
"github.com/stretchr/testify/require"
10+
"github.com/xanygo/anygo/xt"
1111
)
1212

1313
func TestFieldInfo_Equals(t *testing.T) {
@@ -130,7 +130,7 @@ func TestFieldInfo_Equals(t *testing.T) {
130130
for _, tt := range tests {
131131
t.Run(tt.name, func(t *testing.T) {
132132
got := tt.field1.Equals(tt.field2)
133-
require.Equal(t, tt.equal, got, "Fields should be equal: %v", tt.equal)
133+
xt.Equal(t, tt.equal, got)
134134
})
135135
}
136136
}
@@ -193,7 +193,7 @@ func TestFieldInfo_String(t *testing.T) {
193193
for _, tt := range tests {
194194
t.Run(tt.name, func(t *testing.T) {
195195
got := tt.field.String()
196-
require.Equal(t, tt.want, got)
196+
xt.Equal(t, tt.want, got)
197197
})
198198
}
199199
}

internal/schema_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/elliotchance/orderedmap"
12-
"github.com/stretchr/testify/require"
12+
"github.com/xanygo/anygo/xt"
1313
)
1414

1515
func testLoadFile(name string) string {
@@ -85,7 +85,7 @@ func TestParseSchema(t *testing.T) {
8585
got := ParseSchema(tt.args.schema)
8686
gs := got.String()
8787
ws := tt.want.String()
88-
require.Equal(t, ws, gs)
88+
xt.Equal(t, ws, gs)
8989
})
9090
}
9191
}

internal/sync.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"slices"
77
"strings"
88

9-
"github.com/fatih/color"
9+
"github.com/xanygo/anygo/cli/xcolor"
1010
)
1111

1212
// SchemaSync 配置文件
@@ -402,7 +402,8 @@ func (sc *SchemaSync) getSchemaDiff(alter *TableAlterData) []string {
402402
// SyncSQL4Dest sync schema change
403403
func (sc *SchemaSync) SyncSQL4Dest(sqlStr string, sqls []string) error {
404404
sqlStr = strings.TrimSpace(sqlStr)
405-
log.Print("Exec_SQL:\n>>>>>>\n", color.GreenString(sqlStr), "\n<<<<<<<<\n\n")
405+
xcolor.Green(sqlStr)
406+
log.Print("Exec_SQL:\n>>>>>>\n", xcolor.GreenString(sqlStr), "\n<<<<<<<<\n\n")
406407
if len(sqlStr) == 0 {
407408
log.Println("sql_is_empty, skip")
408409
return nil

internal/sync_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package internal
77
import (
88
"testing"
99

10-
"github.com/stretchr/testify/require"
10+
"github.com/xanygo/anygo/xt"
1111
)
1212

1313
func TestSchemaSync_getAlterDataBySchema(t *testing.T) {
@@ -99,7 +99,7 @@ func TestSchemaSync_getAlterDataBySchema(t *testing.T) {
9999
t.Run(tt.name, func(t *testing.T) {
100100
got := tt.sc.getAlterDataBySchema(tt.args.table, tt.args.sSchema, tt.args.dSchema, tt.args.cfg)
101101
t.Log("got alter:\n", got.String())
102-
require.Equal(t, tt.want, got.String())
102+
xt.Equal(t, tt.want, got.String())
103103
})
104104
}
105105
}

0 commit comments

Comments
 (0)