binlog.go 779 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package binlog
  2. import (
  3. "fmt"
  4. )
  5. func (c *Conn) registerAsSlave() error {
  6. brsc := &BinlogRegisterSlaveCommand{
  7. Status: COMMAND_REGISTER_SLAVE,
  8. ServerId: c.Config.ServerId,
  9. Hostname: "",
  10. User: "",
  11. Password: "",
  12. Port: 0,
  13. ReplRank: 0,
  14. MasterId: 0,
  15. }
  16. return c.writeBinlogRegisterSlaveCommand(brsc)
  17. }
  18. func (c *Conn) startBinlogStream() error {
  19. bldc := &BinlogDumpCommand{
  20. Status: COMMAND_BIN_LOG_DUMP,
  21. Position: 120,
  22. Flags: BINLOG_DUMP_NON_BLOCK,
  23. ServerId: c.Config.ServerId,
  24. Filename: c.Config.BinlogFile,
  25. }
  26. return c.writeBinlogDumpCommand(bldc)
  27. }
  28. func (c *Conn) listenForBinlog() error {
  29. for {
  30. p, err := c.readPacket()
  31. if err != nil {
  32. return err
  33. } else {
  34. kp := p.(*OKPacket)
  35. fmt.Printf("kp = %+v\n", kp)
  36. }
  37. }
  38. }