Skip to content

Commit 443bd09

Browse files
authored
Update README.md (#511)
* Update README.md
1 parent f5700cc commit 443bd09

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

README.md

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ You can use it as a MySQL slave to sync binlog from master then do something, li
2323

2424
```go
2525
import (
26-
"github.com/siddontang/go-mysql/replication"
27-
"os"
26+
"github.com/siddontang/go-mysql/replication"
27+
"os"
2828
)
2929
// Create a binlog syncer with a unique server id, the server id must be different from other MySQL's.
3030
// flavor is mysql or mariadb
3131
cfg := replication.BinlogSyncerConfig {
32-
ServerID: 100,
33-
Flavor: "mysql",
34-
Host: "127.0.0.1",
35-
Port: 3306,
36-
User: "root",
37-
Password: "",
32+
ServerID: 100,
33+
Flavor: "mysql",
34+
Host: "127.0.0.1",
35+
Port: 3306,
36+
User: "root",
37+
Password: "",
3838
}
3939
syncer := replication.NewBinlogSyncer(cfg)
4040

@@ -47,23 +47,23 @@ streamer, _ := syncer.StartSync(mysql.Position{binlogFile, binlogPos})
4747
// the mariadb GTID set likes this "0-1-100"
4848

4949
for {
50-
ev, _ := streamer.GetEvent(context.Background())
51-
// Dump event
52-
ev.Dump(os.Stdout)
50+
ev, _ := streamer.GetEvent(context.Background())
51+
// Dump event
52+
ev.Dump(os.Stdout)
5353
}
5454

5555
// or we can use a timeout context
5656
for {
57-
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
58-
ev, err := s.GetEvent(ctx)
59-
cancel()
57+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
58+
ev, err := s.GetEvent(ctx)
59+
cancel()
6060

61-
if err == context.DeadlineExceeded {
62-
// meet timeout
63-
continue
64-
}
61+
if err == context.DeadlineExceeded {
62+
// meet timeout
63+
continue
64+
}
6565

66-
ev.Dump(os.Stdout)
66+
ev.Dump(os.Stdout)
6767
}
6868
```
6969

@@ -117,16 +117,16 @@ cfg.Dump.Tables = []string{"canal_test"}
117117
c, err := NewCanal(cfg)
118118

119119
type MyEventHandler struct {
120-
DummyEventHandler
120+
DummyEventHandler
121121
}
122122

123123
func (h *MyEventHandler) OnRow(e *RowsEvent) error {
124-
log.Infof("%s %v\n", e.Action, e.Rows)
125-
return nil
124+
log.Infof("%s %v\n", e.Action, e.Rows)
125+
return nil
126126
}
127127

128128
func (h *MyEventHandler) String() string {
129-
return "MyEventHandler"
129+
return "MyEventHandler"
130130
}
131131

132132
// Register a handler to handle RowsEvent
@@ -146,7 +146,7 @@ Client package supports a simple MySQL connection driver which you can use it to
146146

147147
```go
148148
import (
149-
"github.com/siddontang/go-mysql/client"
149+
"github.com/siddontang/go-mysql/client"
150150
)
151151

152152
// Connect MySQL at 127.0.0.1:3306, with user root, an empty password and database test
@@ -155,7 +155,7 @@ conn, _ := client.Connect("127.0.0.1:3306", "root", "", "test")
155155
// Or to use SSL/TLS connection if MySQL server supports TLS
156156
//conn, _ := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.UseSSL(true)})
157157

158-
// or to set your own client-side certificates for identity verification for security
158+
// Or to set your own client-side certificates for identity verification for security
159159
//tlsConfig := NewClientTLSConfig(caPem, certPem, keyPem, false, "your-server-name")
160160
//conn, _ := client.Connect("127.0.0.1:3306", "root", "", "test", func(c *Conn) {c.SetTLSConfig(tlsConfig)})
161161

@@ -181,13 +181,13 @@ v, _ = r.GetIntByName(0, "id")
181181

182182
// Direct access to fields
183183
for _, row := range r.Values {
184-
for _, val := range row {
185-
_ = val.Value() // interface{}
186-
// or
187-
if val.Type == mysql.FieldValueTypeFloat {
188-
_ = val.AsFloat64() // float64
189-
}
190-
}
184+
for _, val := range row {
185+
_ = val.Value() // interface{}
186+
// or
187+
if val.Type == mysql.FieldValueTypeFloat {
188+
_ = val.AsFloat64() // float64
189+
}
190+
}
191191
}
192192
```
193193

@@ -207,8 +207,8 @@ so that most MySQL clients should be able to connect to the Server without modif
207207

208208
```go
209209
import (
210-
"github.com/siddontang/go-mysql/server"
211-
"net"
210+
"github.com/siddontang/go-mysql/server"
211+
"net"
212212
)
213213

214214
l, _ := net.Listen("tcp", "127.0.0.1:4000")
@@ -220,7 +220,7 @@ c, _ := l.Accept()
220220
conn, _ := server.NewConn(c, "root", "", server.EmptyHandler{})
221221

222222
for {
223-
conn.HandleCommand()
223+
conn.HandleCommand()
224224
}
225225
```
226226

@@ -259,16 +259,16 @@ Driver is the package that you can use go-mysql with go database/sql like other
259259
package main
260260

261261
import (
262-
"database/sql"
262+
"database/sql"
263263

264-
_ "github.com/siddontang/go-mysql/driver"
264+
_ "github.com/siddontang/go-mysql/driver"
265265
)
266266

267267
func main() {
268-
// dsn format: "user:password@addr?dbname"
269-
dsn := "[email protected]:3306?test"
270-
db, _ := sql.Open(dsn)
271-
db.Close()
268+
// dsn format: "user:password@addr?dbname"
269+
dsn := "[email protected]:3306?test"
270+
db, _ := sql.Open(dsn)
271+
db.Close()
272272
}
273273
```
274274

0 commit comments

Comments
 (0)