forked from compose/transporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmysql.go
70 lines (57 loc) · 1.64 KB
/
mysql.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package mysql
import (
"sync"
"github.com/compose/transporter/adaptor"
"github.com/compose/transporter/client"
//_ "github.com/go-sql-driver/mysql" // import mysql driver
_ "github.com/go-mysql-org/go-mysql/driver" // import alternative mysql driver
)
const (
description = "a mysql adaptor that functions as both a source and a sink"
sampleConfig = `{
"uri": "${MYSQL_URI}",
// "tail": false,
// "cacert": "/path/to/cert.pem",
// "servername": "${MYSQL_DOMAIN}",
}`
)
var (
_ adaptor.Adaptor = &mysql{}
)
// MySQL is an adaptor to read / write to mysql.
// it works as a source by copying files, and then optionally tailing the binlog
type mysql struct {
adaptor.BaseConfig
Tail bool `json:"tail" doc:"if tail is true, then the mysql source will tail the binlog after copying the namespace"`
CACert string `json:"cacert" doc:"path to CA cert"`
ServerName string `json:"servername" doc:"if a separate servername is needed to verify the certificate against. Requires cacert"`
}
func init() {
adaptor.Add(
"mysql",
func() adaptor.Adaptor {
return &mysql{}
},
)
}
func (m *mysql) Client() (client.Client, error) {
return NewClient(WithURI(m.URI),
WithCustomTLS(m.URI, m.CACert, m.ServerName))
}
func (m *mysql) Reader() (client.Reader, error) {
if m.Tail {
return newTailer(m.URI), nil
}
return newReader(), nil
}
func (m *mysql) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) {
return newWriter(), nil
}
// Description for mysql adaptor
func (m *mysql) Description() string {
return description
}
// SampleConfig for mysql adaptor
func (m *mysql) SampleConfig() string {
return sampleConfig
}