From ff82102e12229b84fdf591c538ce257bee6d3339 Mon Sep 17 00:00:00 2001 From: Reinier Schoof Date: Wed, 17 Aug 2022 12:33:45 +0200 Subject: [PATCH 1/3] removed use of deprecated ioutil --- canal/canal.go | 4 ++-- canal/config.go | 3 +-- dump/schema_test.go | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/canal/canal.go b/canal/canal.go index 4784fe4b2..27799de80 100644 --- a/canal/canal.go +++ b/canal/canal.go @@ -3,7 +3,7 @@ package canal import ( "context" "fmt" - "io/ioutil" + "io" "os" "regexp" "strconv" @@ -165,7 +165,7 @@ func (c *Canal) prepareDumper() error { } if c.cfg.Dump.DiscardErr { - c.dumper.SetErrOut(ioutil.Discard) + c.dumper.SetErrOut(io.Discard) } else { c.dumper.SetErrOut(os.Stderr) } diff --git a/canal/config.go b/canal/config.go index 4f4a8ea53..47a1e81cd 100644 --- a/canal/config.go +++ b/canal/config.go @@ -2,7 +2,6 @@ package canal import ( "crypto/tls" - "io/ioutil" "math/rand" "net" "os" @@ -99,7 +98,7 @@ type Config struct { } func NewConfigWithFile(name string) (*Config, error) { - data, err := ioutil.ReadFile(name) + data, err := os.ReadFile(name) if err != nil { return nil, errors.Trace(err) } diff --git a/dump/schema_test.go b/dump/schema_test.go index 52d69a752..e9497f93c 100644 --- a/dump/schema_test.go +++ b/dump/schema_test.go @@ -3,7 +3,7 @@ package dump import ( "bytes" "fmt" - "io/ioutil" + "io" "os" "github.com/go-mysql-org/go-mysql/client" @@ -83,19 +83,19 @@ func (s *schemaTestSuite) TestDump(c *C) { // Using mysql 5.7 can't work, error: // mysqldump: Error 1412: Table definition has changed, // please retry transaction when dumping table `test_replication` at row: 0 - // err := s.d.Dump(ioutil.Discard) + // err := s.d.Dump(io.Discard) // c.Assert(err, IsNil) s.d.AddDatabases("test1", "test2") s.d.AddIgnoreTables("test1", "t2") - err := s.d.Dump(ioutil.Discard) + err := s.d.Dump(io.Discard) c.Assert(err, IsNil) s.d.AddTables("test1", "t1") - err = s.d.Dump(ioutil.Discard) + err = s.d.Dump(io.Discard) c.Assert(err, IsNil) } From d9cdf791228b69ccf480a5318208943872eadac0 Mon Sep 17 00:00:00 2001 From: Reinier Schoof Date: Wed, 17 Aug 2022 17:34:24 +0200 Subject: [PATCH 2/3] fixed goimports linting --- client/auth.go | 6 +++--- client/client_test.go | 4 ++-- client/conn.go | 24 +++++++++++------------- client/pool.go | 8 ++++---- driver/driver.go | 3 +-- failover/failover.go | 13 ++++++------- packet/conn.go | 4 +--- server/caching_sha2_cache_test.go | 2 +- server/conn.go | 4 +--- 9 files changed, 30 insertions(+), 38 deletions(-) diff --git a/client/auth.go b/client/auth.go index 8410edc40..a9fd48099 100644 --- a/client/auth.go +++ b/client/auth.go @@ -110,9 +110,9 @@ func (c *Conn) readInitialHandshake() error { // generate auth response data according to auth plugin // // NOTE: the returned boolean value indicates whether to add a \NUL to the end of data. -// it is quite tricky because MySQL server expects different formats of responses in different auth situations. -// here the \NUL needs to be added when sending back the empty password or cleartext password in 'sha256_password' -// authentication. +// it is quite tricky because MySQL server expects different formats of responses in different auth situations. +// here the \NUL needs to be added when sending back the empty password or cleartext password in 'sha256_password' +// authentication. func (c *Conn) genAuthResponse(authData []byte) ([]byte, bool, error) { // password hashing switch c.authPluginName { diff --git a/client/client_test.go b/client/client_test.go index ae1890770..6e2b53fac 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -112,8 +112,8 @@ func (s *clientTestSuite) TestConn_SetCapability(c *C) { } // NOTE for MySQL 5.5 and 5.6, server side has to config SSL to pass the TLS test, otherwise, it will throw error that -// MySQL server does not support TLS required by the client. However, for MySQL 5.7 and above, auto generated certificates -// are used by default so that manual config is no longer necessary. +// MySQL server does not support TLS required by the client. However, for MySQL 5.7 and above, auto generated certificates +// are used by default so that manual config is no longer necessary. func (s *clientTestSuite) TestConn_TLS_Verify(c *C) { // Verify that the provided tls.Config is used when attempting to connect to mysql. // An empty tls.Config will result in a connection error. diff --git a/client/conn.go b/client/conn.go index 851f2003a..bcbb6f58c 100644 --- a/client/conn.go +++ b/client/conn.go @@ -217,11 +217,10 @@ func (c *Conn) Execute(command string, args ...interface{}) (*Result, error) { // // Example: // -// queries := "SELECT 1; SELECT NOW();" -// conn.ExecuteMultiple(queries, func(result *mysql.Result, err error) { -// // Use the result as you want -// }) -// +// queries := "SELECT 1; SELECT NOW();" +// conn.ExecuteMultiple(queries, func(result *mysql.Result, err error) { +// // Use the result as you want +// }) func (c *Conn) ExecuteMultiple(query string, perResultCallback ExecPerResultCallback) (*Result, error) { if err := c.writeCommandStr(COM_QUERY, query); err != nil { return nil, errors.Trace(err) @@ -271,20 +270,19 @@ func (c *Conn) ExecuteMultiple(query string, perResultCallback ExecPerResultCall } // ExecuteSelectStreaming will call perRowCallback for every row in resultset -// WITHOUT saving any row data to Result.{Values/RawPkg/RowDatas} fields. +// WITHOUT saving any row data to Result.{Values/RawPkg/RowDatas} fields. // When given, perResultCallback will be called once per result // // ExecuteSelectStreaming should be used only for SELECT queries with a large response resultset for memory preserving. // // Example: // -// var result mysql.Result -// conn.ExecuteSelectStreaming(`SELECT ... LIMIT 100500`, &result, func(row []mysql.FieldValue) error { -// // Use the row as you want. -// // You must not save FieldValue.AsString() value after this callback is done. Copy it if you need. -// return nil -// }, nil) -// +// var result mysql.Result +// conn.ExecuteSelectStreaming(`SELECT ... LIMIT 100500`, &result, func(row []mysql.FieldValue) error { +// // Use the row as you want. +// // You must not save FieldValue.AsString() value after this callback is done. Copy it if you need. +// return nil +// }, nil) func (c *Conn) ExecuteSelectStreaming(command string, result *Result, perRowCallback SelectPerRowCallback, perResultCallback SelectPerResultCallback) error { if err := c.writeCommandStr(COM_QUERY, command); err != nil { return errors.Trace(err) diff --git a/client/pool.go b/client/pool.go index 029487e41..263d52773 100644 --- a/client/pool.go +++ b/client/pool.go @@ -75,10 +75,10 @@ var ( ) // NewPool initializes new connection pool and uses params: addr, user, password, dbName and options. -// minAlive specifies the minimum number of open connections that the pool will try to maintain. -// maxAlive specifies the maximum number of open connections -// (for internal reasons, may be greater by 1 inside newConnectionProducer). -// maxIdle specifies the maximum number of idle connections (see DefaultIdleTimeout). +// minAlive specifies the minimum number of open connections that the pool will try to maintain. +// maxAlive specifies the maximum number of open connections (for internal reasons, +// may be greater by 1 inside newConnectionProducer). +// maxIdle specifies the maximum number of idle connections (see DefaultIdleTimeout). func NewPool( logFunc LogFunc, minAlive int, diff --git a/driver/driver.go b/driver/driver.go index 482cffafa..b86c4b374 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -304,8 +304,7 @@ func init() { // Example of supplying a custom CA, no client cert, no key, validating the // certificate, and supplying a serverName for the validation: // -// driver.SetCustomTLSConfig(CaPem, make([]byte, 0), make([]byte, 0), false, "my.domain.name") -// +// driver.SetCustomTLSConfig(CaPem, make([]byte, 0), make([]byte, 0), false, "my.domain.name") func SetCustomTLSConfig(dsn string, caPem []byte, certPem []byte, keyPem []byte, insecureSkipVerify bool, serverName string) error { // Extract addr from dsn parsed, err := url.Parse(dsn) diff --git a/failover/failover.go b/failover/failover.go index 8fbd65c71..6b76122ae 100644 --- a/failover/failover.go +++ b/failover/failover.go @@ -6,15 +6,14 @@ import ( ) // Failover will do below things after the master down -// 1. Elect a slave which has the most up-to-date data with old master -// 2. Promote the slave to new master -// 3. Change other slaves to the new master +// 1. Elect a slave which has the most up-to-date data with old master +// 2. Promote the slave to new master +// 3. Change other slaves to the new master // // Limitation: -// 1, All slaves must have the same master before, Failover will check using master server id or uuid -// 2, If the failover error, the whole topology may be wrong, we must handle this error manually -// 3, Slaves must have same replication mode, all use GTID or not -// +// 1, All slaves must have the same master before, Failover will check using master server id or uuid +// 2, If the failover error, the whole topology may be wrong, we must handle this error manually +// 3, Slaves must have same replication mode, all use GTID or not func Failover(flavor string, slaves []*Server) ([]*Server, error) { var h Handler var err error diff --git a/packet/conn.go b/packet/conn.go index 60de437c4..4d2a2ccfd 100644 --- a/packet/conn.go +++ b/packet/conn.go @@ -40,9 +40,7 @@ func (b *BufPool) Return(buf *bytes.Buffer) { b.pool.Put(buf) } -/* - Conn is the base class to handle MySQL protocol. -*/ +// Conn is the base class to handle MySQL protocol. type Conn struct { net.Conn diff --git a/server/caching_sha2_cache_test.go b/server/caching_sha2_cache_test.go index 0eb0574e2..3be0418d0 100644 --- a/server/caching_sha2_cache_test.go +++ b/server/caching_sha2_cache_test.go @@ -21,7 +21,7 @@ var delay = 50 // test caching for 'caching_sha2_password' // NOTE the idea here is to plugin a throttled credential provider so that the first connection (cache miss) will take longer time -// than the second connection (cache hit). Remember to set the password for MySQL user otherwise it won't cache empty password. +// than the second connection (cache hit). Remember to set the password for MySQL user otherwise it won't cache empty password. func TestCachingSha2Cache(t *testing.T) { log.SetLevel(log.LevelDebug) diff --git a/server/conn.go b/server/conn.go index 92aa8fa8d..e71d9d42c 100644 --- a/server/conn.go +++ b/server/conn.go @@ -11,9 +11,7 @@ import ( "github.com/go-mysql-org/go-mysql/packet" ) -/* - Conn acts like a MySQL server connection, you can use MySQL client to communicate with it. -*/ +// Conn acts like a MySQL server connection, you can use MySQL client to communicate with it. type Conn struct { *packet.Conn From 746029a1556261ff11aa8a4c8593ba88f9d89ae5 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Tue, 23 Aug 2022 11:02:17 +0800 Subject: [PATCH 3/3] remove go1.15 from CI Signed-off-by: lance6716 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fbfe6c242..b82a960be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ jobs: test: strategy: matrix: - go: [ 1.18, 1.17, 1.16, 1.15 ] + go: [ 1.18, 1.17, 1.16 ] name: Tests Go ${{ matrix.go }} runs-on: ubuntu-18.04