Skip to content

Commit

Permalink
Merge branch 'master' of github.com:go-mysql-org/go-mysql into update…
Browse files Browse the repository at this point in the history
…_readme

Signed-off-by: lance6716 <[email protected]>
  • Loading branch information
lance6716 committed Dec 6, 2024
2 parents 6e48ab4 + 506416d commit b93dfec
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jobs:
test:
strategy:
matrix:
go: [ "1.22", "1.21" ]
os: [ ubuntu-22.04, ubuntu-20.04 ]
go: [ "1.23", "1.22" ]
os: [ ubuntu-24.04, ubuntu-22.04, ubuntu-20.04 ]
name: Tests Go ${{ matrix.go }} on ${{ matrix.os }} # This name is used in main branch protection rules
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -51,8 +51,8 @@ jobs:
strategy:
matrix:
mysql_version:
- 8.0.37
- 8.4.0
- 8.0.40
- 8.4.3
name: Tests with MySQL ${{ matrix.mysql_version }}
runs-on: ubuntu-latest
services:
Expand All @@ -78,7 +78,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"
- name: Run tests
run: |
# separate test to avoid RESET MASTER conflict
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"

- name: Build on ${{ matrix.os }}/${{ matrix.arch }}
run: GOARCH=${{ matrix.arch }} GOOS=${{ matrix.os }} go build ./...
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This repo uses [Changelog](CHANGELOG.md).
* [Client](#client) - Simple MySQL client.
* [Fake server](#server) - server side of the MySQL protocol, as library.
* [database/sql like driver](#driver) - An alternative `database/sql` driver for MySQL.
* [Logging](#logging) - Custom logging options.
* [Migration](#how-to-migrate-to-this-repo) - Information for how to migrate if you used the old location of this project.

## Examples
Expand Down Expand Up @@ -346,7 +347,7 @@ import (
func main() {
// dsn format: "user:password@addr?dbname"
dsn := "[email protected]:3306?test"
db, _ := sql.Open(dsn)
db, _ := sql.Open("mysql", dsn)
db.Close()
}
```
Expand Down Expand Up @@ -497,6 +498,29 @@ func main() {

We pass all tests in https://github.com/bradfitz/go-sql-test using go-mysql driver. :-)

## Logging

Logging by default is send to stdout.

To disable logging completely:
```go
import "github.com/siddontang/go-log/log"
...
nullHandler, _ := log.NewNullHandler()
cfg.Logger = log.NewDefault(nullHandler)
```

To write logging to any [`io.Writer`](https://pkg.go.dev/io#Writer):
```go
import "github.com/siddontang/go-log/log"
...
w := ...
streamHandler, _ := log.NewStreamHandler(w)
cfg.Logger = log.NewDefault(streamHandler)
```

Or you can implement your own [`log.Handler`](https://pkg.go.dev/github.com/siddontang/go-log/log#Handler).

## How to migrate to this repo
To change the used package in your repo it's enough to add this `replace` directive to your `go.mod`:
```
Expand Down
3 changes: 3 additions & 0 deletions canal/canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (c *Canal) prepareDumper() error {
return nil
}

// use the same logger for the dumper
c.dumper.Logger = c.cfg.Logger

dbs := c.cfg.Dump.Databases
tables := c.cfg.Dump.Tables
tableDB := c.cfg.Dump.TableDB
Expand Down
8 changes: 7 additions & 1 deletion dump/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
. "github.com/go-mysql-org/go-mysql/mysql"
"github.com/pingcap/errors"
"github.com/siddontang/go-log/log"
"github.com/siddontang/go-log/loggers"
)

// Unlick mysqldump, Dumper is designed for parsing and syning data easily.
Expand Down Expand Up @@ -49,6 +50,8 @@ type Dumper struct {

mysqldumpVersion string
sourceDataSupported bool

Logger loggers.Advanced
}

func NewDumper(executionPath string, addr string, user string, password string) (*Dumper, error) {
Expand Down Expand Up @@ -93,6 +96,9 @@ func NewDumper(executionPath string, addr string, user string, password string)

d.ErrOut = os.Stderr

streamHandler, _ := log.NewStreamHandler(os.Stdout)
d.Logger = log.NewDefault(streamHandler)

return d, nil
}

Expand Down Expand Up @@ -306,7 +312,7 @@ func (d *Dumper) Dump(w io.Writer) error {
}

args[passwordArgIndex] = "--password=******"
log.Infof("exec mysqldump with %v", args)
d.Logger.Infof("exec mysqldump with %v", args)
args[passwordArgIndex] = passwordArg
cmd := exec.Command(d.ExecutionPath, args...)

Expand Down

0 comments on commit b93dfec

Please sign in to comment.