Skip to content

Commit 14a14f7

Browse files
serprexlance6716
andauthored
lint: gofumpt (#996)
* lint: gofumpt * golangci-lint --fix --------- Co-authored-by: lance6716 <[email protected]>
1 parent c27ce4a commit 14a14f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+262
-236
lines changed

.golangci.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ linters:
33
enable:
44
# All code is ready for:
55
- errcheck
6-
- staticcheck
7-
- typecheck
8-
- unused
9-
- misspell
10-
- nolintlint
6+
- gofumpt
117
- goimports
12-
- nakedret
13-
- unconvert
14-
- whitespace
158
- govet
169
- gosimple
1710
- ineffassign
11+
- misspell
12+
- nakedret
13+
- nolintlint
14+
- staticcheck
15+
- typecheck
16+
- unconvert
17+
- unused
18+
- whitespace
1819
# ToDo:
1920
#- gocritic
2021
#- golint

canal/canal.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ type Canal struct {
5858
}
5959

6060
// canal will retry fetching unknown table's meta after UnknownTableRetryPeriod
61-
var UnknownTableRetryPeriod = time.Second * time.Duration(10)
62-
var ErrExcludedTable = errors.New("excluded table meta")
61+
var (
62+
UnknownTableRetryPeriod = time.Second * time.Duration(10)
63+
ErrExcludedTable = errors.New("excluded table meta")
64+
)
6365

6466
func NewCanal(cfg *Config) (*Canal, error) {
6567
c := new(Canal)

canal/canal_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ func TestCreateTableExp(t *testing.T) {
230230
}
231231
}
232232
}
233+
233234
func TestAlterTableExp(t *testing.T) {
234235
cases := []string{
235236
"ALTER TABLE /*generated by server*/ `mydb`.`mytable` ADD `field2` DATE NULL AFTER `field1`;",

canal/handler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ type EventHandler interface {
2424
String() string
2525
}
2626

27-
type DummyEventHandler struct {
28-
}
27+
type DummyEventHandler struct{}
2928

3029
func (h *DummyEventHandler) OnRotate(*replication.EventHeader, *replication.RotateEvent) error {
3130
return nil
3231
}
32+
3333
func (h *DummyEventHandler) OnTableChanged(*replication.EventHeader, string, string) error {
3434
return nil
3535
}
36+
3637
func (h *DummyEventHandler) OnDDL(*replication.EventHeader, mysql.Position, *replication.QueryEvent) error {
3738
return nil
3839
}
@@ -41,9 +42,11 @@ func (h *DummyEventHandler) OnXID(*replication.EventHeader, mysql.Position) erro
4142
func (h *DummyEventHandler) OnGTID(*replication.EventHeader, mysql.BinlogGTIDEvent) error {
4243
return nil
4344
}
45+
4446
func (h *DummyEventHandler) OnPosSynced(*replication.EventHeader, mysql.Position, mysql.GTIDSet, bool) error {
4547
return nil
4648
}
49+
4750
func (h *DummyEventHandler) OnRowsQueryEvent(*replication.RowsQueryEvent) error {
4851
return nil
4952
}

canal/rows_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,24 @@ func TestRowsEvent_handleUnsigned(t *testing.T) {
2828
// column 10 is out of range and should be ignored, don't panic.
2929
UnsignedColumns: []int{1, 3, 5, 7, 9, 10},
3030
},
31-
Rows: [][]interface{}{{
32-
int8(8), int8(8),
33-
int16(16), int16(16),
34-
int32(32), int32(32),
35-
int64(64), int64(64),
36-
int(128), int(128)},
31+
Rows: [][]interface{}{
32+
{
33+
int8(8), int8(8),
34+
int16(16), int16(16),
35+
int32(32), int32(32),
36+
int64(64), int64(64),
37+
int(128), int(128),
38+
},
3739
},
3840
},
39-
wantRows: [][]interface{}{{
40-
int8(8), uint8(8),
41-
int16(16), uint16(16),
42-
int32(32), uint32(32),
43-
int64(64), uint64(64),
44-
int(128), uint(128)},
41+
wantRows: [][]interface{}{
42+
{
43+
int8(8), uint8(8),
44+
int16(16), uint16(16),
45+
int32(32), uint32(32),
46+
int64(64), uint64(64),
47+
int(128), uint(128),
48+
},
4549
},
4650
},
4751
}

canal/sync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (c *Canal) updateTable(header *replication.EventHeader, db, table string) (
252252
}
253253
return
254254
}
255+
255256
func (c *Canal) updateReplicationDelay(ev *replication.BinlogEvent) {
256257
var newDelay uint32
257258
now := uint32(utils.Now().Unix())

client/common_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"flag"
55
)
66

7-
var testUser = flag.String("user", "root", "MySQL user")
8-
var testPassword = flag.String("pass", "", "MySQL password")
9-
var testDB = flag.String("db", "test", "MySQL test database")
7+
var (
8+
testUser = flag.String("user", "root", "MySQL user")
9+
testPassword = flag.String("pass", "", "MySQL password")
10+
testDB = flag.String("db", "test", "MySQL test database")
11+
)

client/conn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (s *connTestSuite) TestSetQueryAttributes() {
203203
err := s.c.SetQueryAttributes(qa)
204204
require.NoError(s.T(), err)
205205
expected := []mysql.QueryAttribute{
206-
mysql.QueryAttribute{
206+
{
207207
Name: "qattr1",
208208
Value: "qattr1val",
209209
},

client/example_client_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ func Example() {
1111
// Connect MySQL at 127.0.0.1:3306, with user root, an empty password and database test
1212
conn, err := client.Connect("127.0.0.1:3306", "root", "", "test")
1313
// Or to use SSL/TLS connection if MySQL server supports TLS
14-
//conn, err := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.UseSSL(true)})
15-
14+
// conn, err := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.UseSSL(true)})
1615
// Or to set your own client-side certificates for identity verification for security
17-
//tlsConfig := NewClientTLSConfig(caPem, certPem, keyPem, false, "your-server-name")
18-
//conn, err := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.SetTLSConfig(tlsConfig)})
16+
// tlsConfig := NewClientTLSConfig(caPem, certPem, keyPem, false, "your-server-name")
17+
// conn, err := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.SetTLSConfig(tlsConfig)})
1918
if err != nil {
2019
msg := fmt.Sprintf(`
2120
This example needs a MySQL listening on 127.0.0.1:3006 with user "root" and

client/pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,9 @@ func (pool *Pool) ping(conn *Conn) error {
569569
// So before call Close, Call PutConn to put all connections that in use back to connection pool first.
570570
func (pool *Pool) Close() {
571571
pool.cancel()
572-
//wait newConnectionProducer exit.
572+
// wait newConnectionProducer exit.
573573
pool.wg.Wait()
574-
//close idle connections
574+
// close idle connections
575575
pool.synchro.Lock()
576576
for _, connection := range pool.synchro.idleConnections {
577577
pool.synchro.stats.TotalCount--

0 commit comments

Comments
 (0)