File tree 6 files changed +27
-47
lines changed
6 files changed +27
-47
lines changed Original file line number Diff line number Diff line change @@ -11,17 +11,11 @@ import (
11
11
const DefaultCompressionLevel = 6
12
12
13
13
var (
14
- zlibReaderPool * sync.Pool
15
- zlibWriterPool sync.Pool
16
- )
17
-
18
- func init () {
19
- zlibReaderPool = & sync.Pool {
14
+ zlibReaderPool = sync.Pool {
20
15
New : func () interface {} {
21
16
return nil
22
17
},
23
18
}
24
-
25
19
zlibWriterPool = sync.Pool {
26
20
New : func () interface {} {
27
21
w , err := zlib .NewWriterLevel (new (bytes.Buffer ), DefaultCompressionLevel )
@@ -31,7 +25,7 @@ func init() {
31
25
return w
32
26
},
33
27
}
34
- }
28
+ )
35
29
36
30
var _ io.WriteCloser = zlibWriter {}
37
31
var _ io.ReadCloser = zlibReader {}
Original file line number Diff line number Diff line change @@ -27,7 +27,12 @@ var customTLSMutex sync.Mutex
27
27
var (
28
28
dsnRegex = regexp .MustCompile ("@[^@]+/[^@/]+" )
29
29
customTLSConfigMap = make (map [string ]* tls.Config )
30
- options = make (map [string ]DriverOption )
30
+ options = map [string ]DriverOption {
31
+ "compress" : CompressOption ,
32
+ "collation" : CollationOption ,
33
+ "readTimeout" : ReadTimeoutOption ,
34
+ "writeTimeout" : WriteTimeoutOption ,
35
+ }
31
36
32
37
// can be provided by clients to allow more control in handling Go and database
33
38
// types beyond the default Value types allowed
@@ -392,11 +397,6 @@ func (r *rows) Next(dest []sqldriver.Value) error {
392
397
var driverName = "mysql"
393
398
394
399
func init () {
395
- options ["compress" ] = CompressOption
396
- options ["collation" ] = CollationOption
397
- options ["readTimeout" ] = ReadTimeoutOption
398
- options ["writeTimeout" ] = WriteTimeoutOption
399
-
400
400
sql .Register (driverName , driver {})
401
401
}
402
402
Original file line number Diff line number Diff line change @@ -23,20 +23,16 @@ type ParseHandler interface {
23
23
Data (schema string , table string , values []string ) error
24
24
}
25
25
26
- var binlogExp * regexp.Regexp
27
- var useExp * regexp.Regexp
28
- var valuesExp * regexp.Regexp
29
- var gtidExp * regexp.Regexp
30
-
31
- func init () {
26
+ var (
32
27
binlogExp = regexp .MustCompile (`^CHANGE (MASTER|REPLICATION SOURCE) TO (MASTER_LOG_FILE|SOURCE_LOG_FILE)='(.+)', (MASTER_LOG_POS|SOURCE_LOG_POS)=(\d+);` )
33
- useExp = regexp .MustCompile ("^USE `(.+)`;" )
28
+ useExp = regexp .MustCompile ("^USE `(.+)`;" )
34
29
valuesExp = regexp .MustCompile ("^INSERT INTO `(.+?)` VALUES \\ ((.+)\\ );$" )
30
+
35
31
// The pattern will only match MySQL GTID, as you know SET GLOBAL gtid_slave_pos='0-1-4' is used for MariaDB.
36
32
// SET @@GLOBAL.GTID_PURGED='1638041a-0457-11e9-bb9f-00505690b730:1-429405150';
37
33
// https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-concepts.html
38
34
gtidExp = regexp .MustCompile (`(\w{8}(-\w{4}){3}-\w{12}(:\d+(-\d+)?)+)` )
39
- }
35
+ )
40
36
41
37
// Parse the dump data with Dumper generate.
42
38
// It can not parse all the data formats with mysqldump outputs
Original file line number Diff line number Diff line change @@ -443,9 +443,7 @@ func init() {
443
443
for i := range EncodeMap {
444
444
EncodeMap [i ] = DONTESCAPE
445
445
}
446
- for i := range EncodeMap {
447
- if to , ok := encodeRef [byte (i )]; ok {
448
- EncodeMap [byte (i )] = to
449
- }
446
+ for k , v := range encodeRef {
447
+ EncodeMap [k ] = v
450
448
}
451
449
}
Original file line number Diff line number Diff line change @@ -2,12 +2,19 @@ package replication
2
2
3
3
import (
4
4
"fmt"
5
- "strings"
6
5
"time"
7
6
)
8
7
9
8
var (
10
- fracTimeFormat []string
9
+ fracTimeFormat = [7 ]string {
10
+ "2006-01-02 15:04:05" ,
11
+ "2006-01-02 15:04:05.0" ,
12
+ "2006-01-02 15:04:05.00" ,
13
+ "2006-01-02 15:04:05.000" ,
14
+ "2006-01-02 15:04:05.0000" ,
15
+ "2006-01-02 15:04:05.00000" ,
16
+ "2006-01-02 15:04:05.000000" ,
17
+ }
11
18
)
12
19
13
20
// fracTime is a help structure wrapping Golang Time.
@@ -56,12 +63,3 @@ func microSecTimestampToTime(ts uint64) time.Time {
56
63
}
57
64
return time .Unix (int64 (ts / 1000000 ), int64 (ts % 1000000 )* 1000 )
58
65
}
59
-
60
- func init () {
61
- fracTimeFormat = make ([]string , 7 )
62
- fracTimeFormat [0 ] = "2006-01-02 15:04:05"
63
-
64
- for i := 1 ; i <= 6 ; i ++ {
65
- fracTimeFormat [i ] = fmt .Sprintf ("2006-01-02 15:04:05.%s" , strings .Repeat ("0" , i ))
66
- }
67
- }
Original file line number Diff line number Diff line change @@ -10,16 +10,10 @@ import (
10
10
"github.com/pingcap/errors"
11
11
)
12
12
13
- var paramFieldData []byte
14
- var columnFieldData []byte
15
-
16
- func init () {
17
- var p = & Field {Name : []byte ("?" )}
18
- var c = & Field {}
19
-
20
- paramFieldData = p .Dump ()
21
- columnFieldData = c .Dump ()
22
- }
13
+ var (
14
+ paramFieldData = (& Field {Name : []byte ("?" )}).Dump ()
15
+ columnFieldData = (& Field {}).Dump ()
16
+ )
23
17
24
18
type Stmt struct {
25
19
ID uint32
You can’t perform that action at this time.
0 commit comments