Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: gofumpt #996

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ linters:
enable:
# All code is ready for:
- errcheck
- staticcheck
- typecheck
- unused
- misspell
- nolintlint
- gofumpt
- goimports
- nakedret
- unconvert
- whitespace
- govet
- gosimple
- ineffassign
- misspell
- nakedret
- nolintlint
- staticcheck
- typecheck
- unconvert
- unused
- whitespace
# ToDo:
#- gocritic
#- golint
Expand Down
6 changes: 4 additions & 2 deletions canal/canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ type Canal struct {
}

// canal will retry fetching unknown table's meta after UnknownTableRetryPeriod
var UnknownTableRetryPeriod = time.Second * time.Duration(10)
var ErrExcludedTable = errors.New("excluded table meta")
var (
UnknownTableRetryPeriod = time.Second * time.Duration(10)
ErrExcludedTable = errors.New("excluded table meta")
)

func NewCanal(cfg *Config) (*Canal, error) {
c := new(Canal)
Expand Down
1 change: 1 addition & 0 deletions canal/canal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func TestCreateTableExp(t *testing.T) {
}
}
}

func TestAlterTableExp(t *testing.T) {
cases := []string{
"ALTER TABLE /*generated by server*/ `mydb`.`mytable` ADD `field2` DATE NULL AFTER `field1`;",
Expand Down
7 changes: 5 additions & 2 deletions canal/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ type EventHandler interface {
String() string
}

type DummyEventHandler struct {
}
type DummyEventHandler struct{}

func (h *DummyEventHandler) OnRotate(*replication.EventHeader, *replication.RotateEvent) error {
return nil
}

func (h *DummyEventHandler) OnTableChanged(*replication.EventHeader, string, string) error {
return nil
}

func (h *DummyEventHandler) OnDDL(*replication.EventHeader, mysql.Position, *replication.QueryEvent) error {
return nil
}
Expand All @@ -41,9 +42,11 @@ func (h *DummyEventHandler) OnXID(*replication.EventHeader, mysql.Position) erro
func (h *DummyEventHandler) OnGTID(*replication.EventHeader, mysql.BinlogGTIDEvent) error {
return nil
}

func (h *DummyEventHandler) OnPosSynced(*replication.EventHeader, mysql.Position, mysql.GTIDSet, bool) error {
return nil
}

func (h *DummyEventHandler) OnRowsQueryEvent(*replication.RowsQueryEvent) error {
return nil
}
Expand Down
28 changes: 16 additions & 12 deletions canal/rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ func TestRowsEvent_handleUnsigned(t *testing.T) {
// column 10 is out of range and should be ignored, don't panic.
UnsignedColumns: []int{1, 3, 5, 7, 9, 10},
},
Rows: [][]interface{}{{
int8(8), int8(8),
int16(16), int16(16),
int32(32), int32(32),
int64(64), int64(64),
int(128), int(128)},
Rows: [][]interface{}{
{
int8(8), int8(8),
int16(16), int16(16),
int32(32), int32(32),
int64(64), int64(64),
int(128), int(128),
},
},
},
wantRows: [][]interface{}{{
int8(8), uint8(8),
int16(16), uint16(16),
int32(32), uint32(32),
int64(64), uint64(64),
int(128), uint(128)},
wantRows: [][]interface{}{
{
int8(8), uint8(8),
int16(16), uint16(16),
int32(32), uint32(32),
int64(64), uint64(64),
int(128), uint(128),
},
},
},
}
Expand Down
1 change: 1 addition & 0 deletions canal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func (c *Canal) updateTable(header *replication.EventHeader, db, table string) (
}
return
}

func (c *Canal) updateReplicationDelay(ev *replication.BinlogEvent) {
var newDelay uint32
now := uint32(utils.Now().Unix())
Expand Down
8 changes: 5 additions & 3 deletions client/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"flag"
)

var testUser = flag.String("user", "root", "MySQL user")
var testPassword = flag.String("pass", "", "MySQL password")
var testDB = flag.String("db", "test", "MySQL test database")
var (
testUser = flag.String("user", "root", "MySQL user")
testPassword = flag.String("pass", "", "MySQL password")
testDB = flag.String("db", "test", "MySQL test database")
)
2 changes: 1 addition & 1 deletion client/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (s *connTestSuite) TestSetQueryAttributes() {
err := s.c.SetQueryAttributes(qa)
require.NoError(s.T(), err)
expected := []mysql.QueryAttribute{
mysql.QueryAttribute{
{
Name: "qattr1",
Value: "qattr1val",
},
Expand Down
7 changes: 3 additions & 4 deletions client/example_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ func Example() {
// Connect MySQL at 127.0.0.1:3306, with user root, an empty password and database test
conn, err := client.Connect("127.0.0.1:3306", "root", "", "test")
// Or to use SSL/TLS connection if MySQL server supports TLS
//conn, err := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.UseSSL(true)})

// conn, err := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.UseSSL(true)})
// Or to set your own client-side certificates for identity verification for security
//tlsConfig := NewClientTLSConfig(caPem, certPem, keyPem, false, "your-server-name")
//conn, err := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.SetTLSConfig(tlsConfig)})
// tlsConfig := NewClientTLSConfig(caPem, certPem, keyPem, false, "your-server-name")
// conn, err := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.SetTLSConfig(tlsConfig)})
if err != nil {
msg := fmt.Sprintf(`
This example needs a MySQL listening on 127.0.0.1:3006 with user "root" and
Expand Down
4 changes: 2 additions & 2 deletions client/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,9 @@ func (pool *Pool) ping(conn *Conn) error {
// So before call Close, Call PutConn to put all connections that in use back to connection pool first.
func (pool *Pool) Close() {
pool.cancel()
//wait newConnectionProducer exit.
// wait newConnectionProducer exit.
pool.wg.Wait()
//close idle connections
// close idle connections
pool.synchro.Lock()
for _, connection := range pool.synchro.idleConnections {
pool.synchro.stats.TotalCount--
Expand Down
8 changes: 4 additions & 4 deletions client/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ func (c *Conn) writeCommand(command byte) error {
c.ResetSequence()

return c.WritePacket([]byte{
0x01, //1 bytes long
0x01, // 1 bytes long
0x00,
0x00,
0x00, //sequence
0x00, // sequence
command,
})
}
Expand Down Expand Up @@ -41,10 +41,10 @@ func (c *Conn) writeCommandUint32(command byte, arg uint32) error {

buf := utils.ByteSliceGet(9)

buf.B[0] = 0x05 //5 bytes long
buf.B[0] = 0x05 // 5 bytes long
buf.B[1] = 0x00
buf.B[2] = 0x00
buf.B[3] = 0x00 //sequence
buf.B[3] = 0x00 // sequence

buf.B[4] = command

Expand Down
8 changes: 3 additions & 5 deletions client/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (c *Conn) readUntilEOF() (err error) {

for {
data, err = c.ReadPacket()

if err != nil {
return
}
Expand All @@ -37,7 +36,7 @@ func (c *Conn) isEOFPacket(data []byte) bool {

func (c *Conn) handleOKPacket(data []byte) (*mysql.Result, error) {
var n int
var pos = 1
pos := 1

r := mysql.NewResultReserveResultset(0)

Expand Down Expand Up @@ -69,7 +68,7 @@ func (c *Conn) handleOKPacket(data []byte) (*mysql.Result, error) {
func (c *Conn) handleErrorPacket(data []byte) error {
e := new(mysql.MyError)

var pos = 1
pos := 1

e.Code = binary.LittleEndian.Uint16(data[pos:])
pos += 2
Expand Down Expand Up @@ -334,7 +333,7 @@ func (c *Conn) readResultsetStreaming(data []byte, binary bool, result *mysql.Re
}

func (c *Conn) readResultColumns(result *mysql.Result) (err error) {
var i = 0
i := 0
var data []byte

for {
Expand Down Expand Up @@ -413,7 +412,6 @@ func (c *Conn) readResultRows(result *mysql.Result, isBinary bool) (err error) {

for i := range result.Values {
result.Values[i], err = result.RowDatas[i].Parse(result.Fields, isBinary, result.Values[i])

if err != nil {
return errors.Trace(err)
}
Expand Down
16 changes: 8 additions & 8 deletions client/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *Stmt) write(args ...interface{}) error {
paramValues := make([][]byte, paramsNum+qaLen)
paramNames := make([][]byte, paramsNum+qaLen)

//NULL-bitmap, length: (num-params+7)
// NULL-bitmap, length: (num-params+7)
nullBitmap := make([]byte, (paramsNum+qaLen+7)>>3)

length := 1 + 4 + 1 + 4 + ((paramsNum + 7) >> 3) + 1 + (paramsNum << 1)
Expand Down Expand Up @@ -195,7 +195,7 @@ func (s *Stmt) write(args ...interface{}) error {
}
data.WriteByte(flags)

//iteration-count, always 1
// iteration-count, always 1
data.Write([]byte{1, 0, 0, 0})

if paramsNum > 0 || (s.conn.capability&mysql.CLIENT_QUERY_ATTRIBUTES > 0 && (flags&mysql.PARAMETER_COUNT_AVAILABLE > 0)) {
Expand All @@ -206,7 +206,7 @@ func (s *Stmt) write(args ...interface{}) error {
if paramsNum > 0 {
data.Write(nullBitmap)

//new-params-bound-flag
// new-params-bound-flag
data.WriteByte(newParamBoundFlag)

if newParamBoundFlag == 1 {
Expand All @@ -219,7 +219,7 @@ func (s *Stmt) write(args ...interface{}) error {
}
}

//value of each parameter
// value of each parameter
for _, v := range paramValues {
data.Write(v)
}
Expand Down Expand Up @@ -253,19 +253,19 @@ func (c *Conn) Prepare(query string) (*Stmt, error) {

pos := 1

//for statement id
// for statement id
s.id = binary.LittleEndian.Uint32(data[pos:])
pos += 4

//number columns
// number columns
s.columns = int(binary.LittleEndian.Uint16(data[pos:]))
pos += 2

//number params
// number params
s.params = int(binary.LittleEndian.Uint16(data[pos:]))
pos += 2

//warnings
// warnings
s.warnings = int(binary.LittleEndian.Uint16(data[pos:]))
// pos += 2

Expand Down
1 change: 0 additions & 1 deletion cmd/go-binlogparser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func main() {
}

err := p.ParseFile(*name, *offset, f)

if err != nil {
println(err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/go-mysqldump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func main() {
d.AddDatabases(subs...)
}

var f = os.Stdout
f := os.Stdout

if len(*output) > 0 {
f, err = os.OpenFile(*output, os.O_CREATE|os.O_WRONLY, 0644)
f, err = os.OpenFile(*output, os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
fmt.Printf("Open file error %v\n", errors.ErrorStack(err))
os.Exit(1)
Expand Down
6 changes: 4 additions & 2 deletions compress/zlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ var (
}
)

var _ io.WriteCloser = zlibWriter{}
var _ io.ReadCloser = zlibReader{}
var (
_ io.WriteCloser = zlibWriter{}
_ io.ReadCloser = zlibReader{}
)

type zlibWriter struct {
w *zlib.Writer
Expand Down
10 changes: 5 additions & 5 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ var (
namedValueCheckers []CheckNamedValueFunc
)

type driver struct {
}
type driver struct{}

type connInfo struct {
standardDSN bool
Expand Down Expand Up @@ -109,7 +108,6 @@ func (d driver) Open(dsn string) (sqldriver.Conn, error) {
)

ci, err := parseDSN(dsn)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -184,8 +182,10 @@ func (d driver) Open(dsn string) (sqldriver.Conn, error) {

type CheckNamedValueFunc func(*sqldriver.NamedValue) error

var _ sqldriver.NamedValueChecker = &conn{}
var _ sqldriver.Validator = &conn{}
var (
_ sqldriver.NamedValueChecker = &conn{}
_ sqldriver.Validator = &conn{}
)

type state struct {
valid bool
Expand Down
2 changes: 1 addition & 1 deletion driver/driver_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (h *mockHandler) handleQuery(query string, binary bool, args []interface{})
case "select":
var r *mysql.Resultset
var err error
//for handle go mysql driver select @@max_allowed_packet
// for handle go mysql driver select @@max_allowed_packet
if strings.Contains(strings.ToLower(query), "max_allowed_packet") {
r, err = mysql.BuildSimpleResultset([]string{"@@max_allowed_packet"}, [][]interface{}{
{mysql.MaxPayloadLen},
Expand Down
8 changes: 5 additions & 3 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"github.com/go-mysql-org/go-mysql/test_util"
)

var testUser = flag.String("user", "root", "MySQL user")
var testPassword = flag.String("pass", "", "MySQL password")
var testDB = flag.String("db", "test", "MySQL test database")
var (
testUser = flag.String("user", "root", "MySQL user")
testPassword = flag.String("pass", "", "MySQL password")
testDB = flag.String("db", "test", "MySQL test database")
)

func TestDriver(t *testing.T) {
suite.Run(t, new(testDriverSuite))
Expand Down
Loading
Loading