Skip to content

Commit fbc3c98

Browse files
committed
Change hostname function name and hid variable.
Made the LocalHost variable private and changed it's name to localhost. Added additional funciton SetLocalHostname to set the hostname to register as. Change getter methods name to match setter. Change it to LocalHostname().
1 parent ec6c17b commit fbc3c98

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

replication/binlogsyncer.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ type BinlogSyncer struct {
2626
c *client.Conn
2727
serverID uint32
2828

29-
// LocalHost is the name of you want to present to the MySQL master. If it is not set it will default to os.Hostname()
30-
LocalHost string
29+
localhost string
3130
host string
3231
port uint16
3332
user string
@@ -65,13 +64,19 @@ func NewBinlogSyncer(serverID uint32, flavor string) *BinlogSyncer {
6564
return b
6665
}
6766

68-
func (b *BinlogSyncer) localhostName() string {
67+
// LocalHostname returns the hostname that register slave would register as.
68+
func (b *BinlogSyncer) LocalHostname() string {
6969

70-
if b.LocalHost == "" {
70+
if b.localhost == "" {
7171
h, _ := os.Hostname()
7272
return h
7373
}
74-
return b.LocalHost
74+
return b.localhost
75+
}
76+
77+
// SetLocalHostname set's the hostname that register salve would register as.
78+
func (b *NewBinlogSyncer) SetLocalHostname(name string) {
79+
b.localhost = name
7580
}
7681

7782
func (b *BinlogSyncer) Close() {
@@ -412,7 +417,7 @@ func (b *BinlogSyncer) writeBinlogDumpMariadbGTIDCommand(gset GTIDSet) error {
412417
func (b *BinlogSyncer) writeRegisterSlaveCommand() error {
413418
b.c.ResetSequence()
414419

415-
hostname := b.localhostName()
420+
hostname := b.LocalHostname()
416421

417422
// This should be the name of slave host not the host we are connecting to.
418423
data := make([]byte, 4+1+4+1+len(hostname)+1+len(b.user)+1+len(b.password)+2+4+4)

0 commit comments

Comments
 (0)