Skip to content

Code refractoring #736

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

Merged
merged 1 commit into from
Nov 15, 2022
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ A simple example:
package main

import (
"github.com/siddontang/go-log/log"
"github.com/go-mysql-org/go-mysql/canal"
"github.com/siddontang/go-log/log"
)

type MyEventHandler struct {
Expand Down
8 changes: 4 additions & 4 deletions canal/canal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,19 @@ func TestDropTableExp(t *testing.T) {

func TestWithoutSchemeExp(t *testing.T) {
cases := []replication.QueryEvent{
replication.QueryEvent{
{
Schema: []byte("test"),
Query: []byte("drop table test0"),
},
replication.QueryEvent{
{
Schema: []byte("test"),
Query: []byte("rename table `test0` to `testtmp`"),
},
replication.QueryEvent{
{
Schema: []byte("test"),
Query: []byte("ALTER TABLE `test0` ADD `field2` DATE NULL AFTER `field1`;"),
},
replication.QueryEvent{
{
Schema: []byte("test"),
Query: []byte("CREATE TABLE IF NOT EXISTS test0 (`id` int(10)) ENGINE=InnoDB"),
},
Expand Down
20 changes: 10 additions & 10 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ func (s *clientTestSuite) TestConn_SetCapability(c *C) {
mysql.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA,
}

for _, cap := range caps {
c.Assert(s.c.ccaps&cap > 0, IsFalse)
s.c.SetCapability(cap)
c.Assert(s.c.ccaps&cap > 0, IsTrue)
s.c.UnsetCapability(cap)
c.Assert(s.c.ccaps&cap > 0, IsFalse)
for _, capI := range caps {
c.Assert(s.c.ccaps&capI > 0, IsFalse)
s.c.SetCapability(capI)
c.Assert(s.c.ccaps&capI > 0, IsTrue)
s.c.UnsetCapability(capI)
c.Assert(s.c.ccaps&capI > 0, IsFalse)
}
}

Expand Down Expand Up @@ -186,7 +186,7 @@ func (s *clientTestSuite) TestConn_Select(c *C) {
c.Assert(ss, Equals, "a")

f, _ := result.GetFloat(0, 1)
c.Assert(f, Equals, float64(3.14))
c.Assert(f, Equals, 3.14)

e, _ := result.GetString(0, 2)
c.Assert(e, Equals, "test1")
Expand All @@ -195,7 +195,7 @@ func (s *clientTestSuite) TestConn_Select(c *C) {
c.Assert(ss, Equals, "a")

f, _ = result.GetFloatByName(0, "f")
c.Assert(f, Equals, float64(3.14))
c.Assert(f, Equals, 3.14)

e, _ = result.GetStringByName(0, "e")
c.Assert(e, Equals, "test1")
Expand Down Expand Up @@ -301,7 +301,7 @@ func (s *clientTestSuite) TestStmt_Select(c *C) {
c.Assert(ss, Equals, "a")

f, _ := result.GetFloat(0, 1)
c.Assert(f, Equals, float64(3.14))
c.Assert(f, Equals, 3.14)

e, _ := result.GetString(0, 2)
c.Assert(e, Equals, "test1")
Expand All @@ -310,7 +310,7 @@ func (s *clientTestSuite) TestStmt_Select(c *C) {
c.Assert(ss, Equals, "a")

f, _ = result.GetFloatByName(0, "f")
c.Assert(f, Equals, float64(3.14))
c.Assert(f, Equals, 3.14)

e, _ = result.GetStringByName(0, "e")
c.Assert(e, Equals, "test1")
Expand Down
2 changes: 1 addition & 1 deletion client/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (c *Conn) readResultsetStreaming(data []byte, binary bool, result *Result,
}

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

for {
Expand Down
2 changes: 1 addition & 1 deletion client/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (s *Stmt) write(args ...interface{}) error {

for i := range args {
if args[i] == nil {
nullBitmap[i/8] |= (1 << (uint(i) % 8))
nullBitmap[i/8] |= 1 << (uint(i) % 8)
paramTypes[i<<1] = MYSQL_TYPE_NULL
continue
}
Expand Down
12 changes: 6 additions & 6 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func TestParseDSN(t *testing.T) {
// Use different numbered domains to more readily see what has failed - since we
// test in a loop we get the same line number on error
testDSNs := map[string]connInfo{
"user:password@localhost?db": connInfo{standardDSN: false, addr: "localhost", user: "user", password: "password", db: "db", params: url.Values{}},
"[email protected]?db": connInfo{standardDSN: false, addr: "1.domain.com", user: "user", password: "", db: "db", params: url.Values{}},
"user:[email protected]/db": connInfo{standardDSN: true, addr: "2.domain.com", user: "user", password: "password", db: "db", params: url.Values{}},
"user:[email protected]/db?ssl=true": connInfo{standardDSN: true, addr: "3.domain.com", user: "user", password: "password", db: "db", params: url.Values{"ssl": []string{"true"}}},
"user:[email protected]/db?ssl=custom": connInfo{standardDSN: true, addr: "4.domain.com", user: "user", password: "password", db: "db", params: url.Values{"ssl": []string{"custom"}}},
"user:[email protected]/db?unused=param": connInfo{standardDSN: true, addr: "5.domain.com", user: "user", password: "password", db: "db", params: url.Values{"unused": []string{"param"}}},
"user:password@localhost?db": {standardDSN: false, addr: "localhost", user: "user", password: "password", db: "db", params: url.Values{}},
"[email protected]?db": {standardDSN: false, addr: "1.domain.com", user: "user", password: "", db: "db", params: url.Values{}},
"user:[email protected]/db": {standardDSN: true, addr: "2.domain.com", user: "user", password: "password", db: "db", params: url.Values{}},
"user:[email protected]/db?ssl=true": {standardDSN: true, addr: "3.domain.com", user: "user", password: "password", db: "db", params: url.Values{"ssl": []string{"true"}}},
"user:[email protected]/db?ssl=custom": {standardDSN: true, addr: "4.domain.com", user: "user", password: "password", db: "db", params: url.Values{"ssl": []string{"custom"}}},
"user:[email protected]/db?unused=param": {standardDSN: true, addr: "5.domain.com", user: "user", password: "password", db: "db", params: url.Values{"unused": []string{"param"}}},
}

for supplied, expected := range testDSNs {
Expand Down
2 changes: 1 addition & 1 deletion failover/mariadb_gtid_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (h *MariadbGTIDHandler) Promote(s *Server) error {
}

func (h *MariadbGTIDHandler) FindBestSlaves(slaves []*Server) ([]*Server, error) {
bestSlaves := []*Server{}
var bestSlaves []*Server

ps := make([]uint64, len(slaves))

Expand Down
2 changes: 1 addition & 1 deletion failover/mysql_gtid_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (h *MysqlGTIDHandler) Promote(s *Server) error {
func (h *MysqlGTIDHandler) FindBestSlaves(slaves []*Server) ([]*Server, error) {
// MHA use Relay_Master_Log_File and Exec_Master_Log_Pos to determind which is the best slave

bestSlaves := []*Server{}
var bestSlaves []*Server

ps := make([]Position, len(slaves))

Expand Down
2 changes: 1 addition & 1 deletion mysql/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (f *Field) Dump() []byte {
f = &Field{}
}
if f.Data != nil {
return []byte(f.Data)
return f.Data
}

l := len(f.Schema) + len(f.Table) + len(f.OrgTable) + len(f.Name) + len(f.OrgName) + len(f.DefaultValue) + 48
Expand Down
4 changes: 2 additions & 2 deletions mysql/resultset_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func BuildSimpleBinaryResultset(names []string, values [][]interface{}) (*Result

var b []byte

bitmapLen := ((len(names) + 7 + 2) >> 3)
bitmapLen := (len(names) + 7 + 2) >> 3

for i, vs := range values {
if len(vs) != len(r.Fields) {
Expand Down Expand Up @@ -220,7 +220,7 @@ func BuildSimpleBinaryResultset(names []string, values [][]interface{}) (*Result
}
}
if value == nil {
nullBitmap[(i+2)/8] |= (1 << (uint(i+2) % 8))
nullBitmap[(i+2)/8] |= 1 << (uint(i+2) % 8)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion replication/binlogsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ func (b *BinlogSyncer) parseEvent(s *BinlogStreamer, data []byte) error {

needACK := false
if b.cfg.SemiSyncEnabled && (data[0] == SemiSyncIndicator) {
needACK = (data[1] == 0x01)
needACK = data[1] == 0x01
//skip semi sync header
data = data[2:]
}
Expand Down
2 changes: 1 addition & 1 deletion replication/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const (

var (
//binlog header [ fe `bin` ]
BinLogFileHeader []byte = []byte{0xfe, 0x62, 0x69, 0x6e}
BinLogFileHeader = []byte{0xfe, 0x62, 0x69, 0x6e}

SemiSyncIndicator byte = 0xef
)
Expand Down
10 changes: 5 additions & 5 deletions replication/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ func (h *EventHeader) Dump(w io.Writer) {
}

var (
checksumVersionSplitMysql []int = []int{5, 6, 1}
checksumVersionProductMysql int = (checksumVersionSplitMysql[0]*256+checksumVersionSplitMysql[1])*256 + checksumVersionSplitMysql[2]
checksumVersionSplitMysql = []int{5, 6, 1}
checksumVersionProductMysql = (checksumVersionSplitMysql[0]*256+checksumVersionSplitMysql[1])*256 + checksumVersionSplitMysql[2]

checksumVersionSplitMariaDB []int = []int{5, 3, 0}
checksumVersionProductMariaDB int = (checksumVersionSplitMariaDB[0]*256+checksumVersionSplitMariaDB[1])*256 + checksumVersionSplitMariaDB[2]
checksumVersionSplitMariaDB = []int{5, 3, 0}
checksumVersionProductMariaDB = (checksumVersionSplitMariaDB[0]*256+checksumVersionSplitMariaDB[1])*256 + checksumVersionSplitMariaDB[2]
)

// server version format X.Y.Zabc, a is not . or number
Expand Down Expand Up @@ -141,7 +141,7 @@ func splitServerVersion(server string) []int {
func calcVersionProduct(server string) int {
versionSplit := splitServerVersion(server)

return ((versionSplit[0]*256+versionSplit[1])*256 + versionSplit[2])
return (versionSplit[0]*256+versionSplit[1])*256 + versionSplit[2]
}

type FormatDescriptionEvent struct {
Expand Down
2 changes: 1 addition & 1 deletion replication/json_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func (d *jsonBinaryDecoder) decodeDateTime(data []byte) interface{} {
year := ym / 13
month := ym % 13
day := ymd % (1 << 5)
hour := (hms >> 12)
hour := hms >> 12
minute := (hms >> 6) % (1 << 6)
second := hms % (1 << 6)
frac := v % (1 << 24)
Expand Down
12 changes: 6 additions & 6 deletions replication/row_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ func (e *TableMapEvent) decodeMeta(data []byte) error {
for i, t := range e.ColumnType {
switch t {
case MYSQL_TYPE_STRING:
var x uint16 = uint16(data[pos]) << 8 //real type
x += uint16(data[pos+1]) //pack or field length
var x = uint16(data[pos]) << 8 //real type
x += uint16(data[pos+1]) //pack or field length
e.ColumnMeta[i] = x
pos += 2
case MYSQL_TYPE_NEWDECIMAL:
var x uint16 = uint16(data[pos]) << 8 //precision
x += uint16(data[pos+1]) //decimals
var x = uint16(data[pos]) << 8 //precision
x += uint16(data[pos+1]) //decimals
e.ColumnMeta[i] = x
pos += 2
case MYSQL_TYPE_VAR_STRING,
Expand Down Expand Up @@ -1002,7 +1002,7 @@ func (e *RowsEvent) parseFracTime(t interface{}) interface{} {

// see mysql sql/log_event.cc log_event_print_value
func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16) (v interface{}, n int, err error) {
var length int = 0
var length = 0

if tp == MYSQL_TYPE_STRING {
if meta >= 256 {
Expand Down Expand Up @@ -1428,7 +1428,7 @@ func decodeDatetime2(data []byte, dec uint16) (interface{}, int, error) {

second := int(hms % (1 << 6))
minute := int((hms >> 6) % (1 << 6))
hour := int((hms >> 12))
hour := int(hms >> 12)

// DATETIME encoding for nonfractional part after MySQL 5.6.4
// https://dev.mysql.com/doc/internals/en/date-and-time-data-type-representation.html
Expand Down
8 changes: 4 additions & 4 deletions replication/row_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,13 +1104,13 @@ func (_ *testDecodeSuite) TestTableMapHelperMaps(c *C) {
}

enumStrValueMap := map[int][]string{
38: []string{"a", "b"},
43: []string{"c", "d"},
38: {"a", "b"},
43: {"c", "d"},
}

setStrValueMap := map[int][]string{
39: []string{"1", "2"},
42: []string{"3", "4"},
39: {"1", "2"},
42: {"3", "4"},
}

geometryTypeMap := map[int]uint64{
Expand Down
14 changes: 7 additions & 7 deletions server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func (t *connTestSuite) TestCapability(c *check.C) {
mysql.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA,
}

for _, cap := range caps {
c.Assert(conn.HasCapability(cap), check.IsFalse)
conn.SetCapability(cap)
c.Assert(conn.HasCapability(cap), check.IsTrue)
c.Assert(conn.Capability()&cap > 0, check.IsTrue)
conn.UnsetCapability(cap)
c.Assert(conn.HasCapability(cap), check.IsFalse)
for _, capI := range caps {
c.Assert(conn.HasCapability(capI), check.IsFalse)
conn.SetCapability(capI)
c.Assert(conn.HasCapability(capI), check.IsTrue)
c.Assert(conn.Capability()&capI > 0, check.IsTrue)
conn.UnsetCapability(capI)
c.Assert(conn.HasCapability(capI), check.IsFalse)
}
}
4 changes: 2 additions & 2 deletions server/resp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func (t *respConnTestSuite) TestConnWriteFieldValues(c *check.C) {
conn := &Conn{Conn: packet.NewConn(clientConn)}

r, err := mysql.BuildSimpleTextResultset([]string{"c"}, [][]interface{}{
[]interface{}{"d"},
[]interface{}{nil},
{"d"},
{nil},
})

c.Assert(err, check.IsNil)
Expand Down