Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: go-mysql-org/go-mysql
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.9.1
Choose a base ref
...
head repository: go-mysql-org/go-mysql
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.10.0
Choose a head ref
  • 19 commits
  • 37 files changed
  • 7 contributors

Commits on Sep 26, 2024

  1. use v1.9.1 instead of v1.9.0

    Signed-off-by: lance6716 <lance6716@gmail.com>
    lance6716 committed Sep 26, 2024
    Copy the full SHA
    a9f9c23 View commit details

Commits on Oct 20, 2024

  1. Ensure ACKs are sent after backup (#921)

    * This commit addresses an issue where acknowledgments (ACKs) were sometimes sent to the master before binlog events were fully written and fsynced to disk during backup operations. Sending ACKs prematurely in semi-synchronous replication could lead to data loss if the replica fails after sending the ACK but before persisting the event.
    
    Key changes:
    
    - Introduced an `EventHandler` interface with a `HandleEvent` method for
      processing binlog events. This allows custom event handling logic to
      be injected into the replication stream.
    
    - Added an `eventHandler` field to `BinlogSyncer` and provided a
      `SetEventHandler` method to assign an event handler. This enables
      `BinlogSyncer` to delegate event processing to the assigned handler.
    
    - Implemented `BackupEventHandler` which writes binlog events to disk
      and ensures that each event is fsynced before returning. This ensures
      data durability before ACKs are sent.
    
    - Modified the `onStream` method in `BinlogSyncer` to separate event
      parsing (`parseEvent`) from event handling and ACK sending
      (`handleEventAndACK`). This adheres to the single-responsibility
      principle and makes the code cleaner.
    
    - Moved state updates (e.g., updating `b.nextPos`) and GTID set handling
      from `parseEvent` to `handleEventAndACK` to avoid side effects during
      parsing.
    
    - Ensured that ACKs are sent only after the event has been fully
      processed and fsynced by sending the ACK in `handleEventAndACK` after
      event handling.
    
    * Refactor event handling by replacing SyncMode and EventHandleMode with SynchronousEventHandler. Simplify the event processing in BinlogSyncerConfig by introducing SynchronousEventHandler for synchronous event handling. Update StartBackup, StartBackupWithHandler, and associated tests to reflect these changes.
    
    * Add some comments and remember to remove SetEventHandler and the eventHandler attribute
    
    * Remove the timeout for synchronous backup, revert the timeout move to return the behavior to 30 days _between_ events, restore some comments, use struct instead of bool as recommended, add a note about SynchronousEventHandler and the parseEvent return values
    
    * Make sure to assign the timeout on the syncer so the backup doesn't fail
    
    * Make sure to add NewBackupHandler in order to expose the otherwise private handler outside the package
    
    ---------
    
    Co-authored-by: Dylan Terry <dterry@dropbox.com>
    dt8269 and Dylan Terry authored Oct 20, 2024
    Copy the full SHA
    c435689 View commit details

Commits on Oct 24, 2024

  1. client: Fix timeout reset during TLS handshake (#925)

    This commit fixes `(*client.Conn).writeAuthHandshake()` to use
    `packet.NewConnWithTimeout` instead of `packet.NewBufferedConn`
    when recreating the packet connection after switching TLS on.
    This preserves the connection read/write timeout settings which
    would otherwise be reset to zero.
    
    Since this code executes after some reads and writes have already
    taken place, and the packet connection code only sets a deadline
    when the timeout values are nonzero, the result was that previously
    when connecting using TLS and with a read and/or write timeout set,
    the connection would inevitably fail just one timeout-duration after
    being opened.
    
    This use of `packet.NewBufferedConn` appears to be the only place
    in the `client` package where a packet connection was recreated
    without the timeout configuration being plumbed through.
    willdonnelly authored Oct 24, 2024
    Copy the full SHA
    ff1dab4 View commit details

Commits on Oct 26, 2024

  1. Makefile: allow for gotip (#928)

    This allows `make GO=gotip build` to work.
    dveeden authored Oct 26, 2024
    Copy the full SHA
    51292e4 View commit details
  2. replication: Make ServerVersion a proper string (#930)

    The ServerVersion is a slice of 50 bytes. If the ServerVersion was
    "9.1.0" then the rest of they bytes would be 0x0.
    
    This caused the printout of the FormatDescriptionEvent in go-mysqlbinlog
    to look weird.
    
    Before:
    
    ```
    === FormatDescriptionEvent ===
    Date: 2024-10-24 14:42:04
    Log position: 127
    Event size: 123
    Version: 4
    Server version: 9.1.0^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
    Checksum algorithm: 1
    ```
    
    After:
    
    ```
    === FormatDescriptionEvent ===
    Date: 2024-10-24 14:42:04
    Log position: 127
    Event size: 123
    Version: 4
    Server version: 9.1.0
    Checksum algorithm: 1
    ```
    
    Co-authored-by: lance6716 <lance6716@gmail.com>
    dveeden and lance6716 authored Oct 26, 2024
    Copy the full SHA
    22158ba View commit details

Commits on Oct 27, 2024

  1. dump: Support newer mysqldump versions (#932)

    Old mysqldump used `CHANGE MASTER TO ...` and newer versions use `CHANGE
    REPLICATION SOURCE ...`.
    
    Co-authored-by: lance6716 <lance6716@gmail.com>
    dveeden and lance6716 authored Oct 27, 2024
    Copy the full SHA
    cadcdcc View commit details
  2. Copy the full SHA
    661b04b View commit details

Commits on Oct 28, 2024

  1. Copy the full SHA
    03f4d7c View commit details
  2. dump: use --source-data based on version (#933)

    * dump: use --source-data based on version
    
    * Fix issue found by linter
    
    ---------
    
    Co-authored-by: lance6716 <lance6716@gmail.com>
    dveeden and lance6716 authored Oct 28, 2024
    Copy the full SHA
    5ad36fa View commit details
  3. server: Improve example (#936)

    * server: Improve example
    
    1. Use the example from the `README.md` and turn it into
       a `go-mysqlserver` binary that users can run.
    2. Add more logging to make it easier to understand what it is doing.
       This is done both in `go-mysqlserver` as well as the `EmptyHandler`
    3. Remove the `server/example` as we already have a example now.
    4. Support the minimal set of queries that MySQL Shell `mysqlsh` needs
       to be able to connect. (tested with MySQL Shell 9.1.0)
    5. Change the default version from 5.7.0 to 8.0.11 (first 8.0 GA
       version)
    
    * Update server/command.go
    
    Co-authored-by: lance6716 <lance6716@gmail.com>
    
    * Update based on review
    
    ---------
    
    Co-authored-by: lance6716 <lance6716@gmail.com>
    dveeden and lance6716 authored Oct 28, 2024
    Copy the full SHA
    5acb569 View commit details

Commits on Nov 8, 2024

  1. go-mysqldump: Add option to skip binlog position (#941)

    When running against MariaDB 11.4 without binlogs enabled:
    
    - `mysqldump` 9.1.0 fails to dump when called with `--source-data` due
      to the `SHOW BINARY LOG STATUS` not being supported by MariaDB.
    - `mariadb-dump` 11.4 fails to dump when called with `--master-data` due
      to binlogs not being enabled.
    
    Other situations where this can be useful:
    
    - Permission issues
    dveeden authored Nov 8, 2024
    Copy the full SHA
    867d4cc View commit details

Commits on Nov 9, 2024

  1. Copy the full SHA
    5b7ff06 View commit details

Commits on Nov 11, 2024

  1. dump: use mariadb-dump when available (#942)

    Co-authored-by: lance6716 <lance6716@gmail.com>
    dveeden and lance6716 authored Nov 11, 2024
    Copy the full SHA
    37a3291 View commit details
  2. Remove failover (#931)

    Co-authored-by: lance6716 <lance6716@gmail.com>
    dveeden and lance6716 authored Nov 11, 2024
    Copy the full SHA
    f230d5f View commit details
  3. canal: support ipv6 address (#943)

    * feat(canal): support ipv6 address
    
    * feat: use net.SplitHostPort to parse ip with ports
    
    * chore: optimze validate error message
    
    * feat(ci): complete test cases
    
    * feat(dumper): use net.SplitHostPort to parse address
    sinomoe authored Nov 11, 2024
    Copy the full SHA
    760b566 View commit details

Commits on Nov 14, 2024

  1. Copy the full SHA
    c7b7533 View commit details

Commits on Nov 19, 2024

  1. Copy the full SHA
    b1f4fb3 View commit details

Commits on Nov 20, 2024

  1. replication,cmd: improve flavor handling (#946)

    For `go-mysqlbinlog` and `go-canal`: return an error for invalid
    flavors.
    
    For `go-mysqlbinlog`: log a non-critical error if the server version has "MariaDB"
    in it but the flavor isn't set to "mariadb".
    
    Co-authored-by: lance6716 <lance6716@gmail.com>
    dveeden and lance6716 authored Nov 20, 2024
    Copy the full SHA
    8b76415 View commit details
  2. new release v1.10.0 (#949)

    * prepare a release
    
    Signed-off-by: lance6716 <lance6716@gmail.com>
    
    * --wip-- [skip ci]
    
    * done
    
    Signed-off-by: lance6716 <lance6716@gmail.com>
    
    ---------
    
    Signed-off-by: lance6716 <lance6716@gmail.com>
    lance6716 authored Nov 20, 2024
    Copy the full SHA
    95109e7 View commit details
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -17,6 +17,11 @@ jobs:
echo -n "mysqldump -V: " ; mysqldump -V
echo -e '[mysqld]\nserver-id=1\nlog-bin=mysql\nbinlog-format=row\ngtid-mode=ON\nenforce_gtid_consistency=ON\n' | sudo tee /etc/mysql/conf.d/replication.cnf
# bind to :: for dual-stack listening
sudo sed -i 's/bind-address.*= 127.0.0.1/bind-address = ::/' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo sed -i 's/mysqlx-bind-address.*= 127.0.0.1/mysqlx-bind-address = ::/' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo service mysql start
# apply this for mysql5 & mysql8 compatibility
@@ -109,5 +114,6 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: Build on ${{ matrix.os }}/${{ matrix.arch }}
run: GOARCH=${{ matrix.arch }} GOOS=${{ matrix.os }} go build ./...
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
### Tag v1.9.0 (2024-09-12)
## Tag v1.10.0 (2024-11-20)
* replication,cmd: improve flavor handling [#946](https://github.com/go-mysql-org/go-mysql/pull/946) ([dveeden](https://github.com/dveeden))
* Upgrade github.com/pingcap/tidb/pkg/parser. [#948](https://github.com/go-mysql-org/go-mysql/pull/948) ([Tang8330](https://github.com/Tang8330))
* replication: Add GTID_TAGGED_LOG_EVENT [#947](https://github.com/go-mysql-org/go-mysql/pull/947) ([dveeden](https://github.com/dveeden))
* canal: support ipv6 address [#943](https://github.com/go-mysql-org/go-mysql/pull/943) ([sinomoe](https://github.com/sinomoe))
* Remove failover [#931](https://github.com/go-mysql-org/go-mysql/pull/931) ([dveeden](https://github.com/dveeden))
* dump: use mariadb-dump when available [#942](https://github.com/go-mysql-org/go-mysql/pull/942) ([dveeden](https://github.com/dveeden))
* go-mysqlbinlog: set to retry only 10 times [#945](https://github.com/go-mysql-org/go-mysql/pull/945) ([dveeden](https://github.com/dveeden))
* go-mysqldump: Add option to skip binlog position [#941](https://github.com/go-mysql-org/go-mysql/pull/941) ([dveeden](https://github.com/dveeden))
* server: Improve example [#936](https://github.com/go-mysql-org/go-mysql/pull/936) ([dveeden](https://github.com/dveeden))
* dump: use --source-data based on version [#933](https://github.com/go-mysql-org/go-mysql/pull/933) ([dveeden](https://github.com/dveeden))
* replication: Log info about server [#935](https://github.com/go-mysql-org/go-mysql/pull/935) ([dveeden](https://github.com/dveeden))
* replication: fix uuid typo [#934](https://github.com/go-mysql-org/go-mysql/pull/934) ([dveeden](https://github.com/dveeden))
* dump: Support newer mysqldump versions [#932](https://github.com/go-mysql-org/go-mysql/pull/932) ([dveeden](https://github.com/dveeden))
* replication: Make ServerVersion a proper string [#930](https://github.com/go-mysql-org/go-mysql/pull/930) ([dveeden](https://github.com/dveeden))
* Makefile: allow for gotip [#928](https://github.com/go-mysql-org/go-mysql/pull/928) ([dveeden](https://github.com/dveeden))
* client: Fix timeout reset during TLS handshake [#925](https://github.com/go-mysql-org/go-mysql/pull/925) ([willdonnelly](https://github.com/willdonnelly))
* Ensure ACKs are sent after backup [#921](https://github.com/go-mysql-org/go-mysql/pull/921) ([dt8269](https://github.com/dt8269))

### Tag v1.9.1 (2024-09-12)
* Fix can't connect to MySQL 8.0 with long password. [#914](https://github.com/go-mysql-org/go-mysql/pull/914) ([lance6716](https://github.com/lance6716))
* Fix actual master and add -race in CI. [#907](https://github.com/go-mysql-org/go-mysql/pull/907) ([atercattus](https://github.com/atercattus))
* export EventCacheCount on Canal Config. [#913](https://github.com/go-mysql-org/go-mysql/pull/913) ([tomwei7](https://github.com/tomwei7))
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
all: build

GO111MODULE=on
MYSQL_VERSION ?= 8.0
GO ?= go

build:
go build -o bin/go-mysqlbinlog cmd/go-mysqlbinlog/main.go
go build -o bin/go-mysqldump cmd/go-mysqldump/main.go
go build -o bin/go-canal cmd/go-canal/main.go
go build -o bin/go-binlogparser cmd/go-binlogparser/main.go
${GO} build -o bin/go-mysqlbinlog cmd/go-mysqlbinlog/main.go
${GO} build -o bin/go-mysqldump cmd/go-mysqldump/main.go
${GO} build -o bin/go-canal cmd/go-canal/main.go
${GO} build -o bin/go-binlogparser cmd/go-binlogparser/main.go
${GO} build -o bin/go-mysqlserver cmd/go-mysqlserver/main.go

test:
go test --race -timeout 2m ./...
${GO} test --race -timeout 2m ./...

MYSQL_VERSION ?= 8.0
test-local:
docker run --rm -d --network=host --name go-mysql-server \
-e MYSQL_ALLOW_EMPTY_PASSWORD=true \
-e MYSQL_DATABASE=test \
-v $${PWD}/docker/resources/replication.cnf:/etc/mysql/conf.d/replication.cnf \
mysql:$(MYSQL_VERSION)
docker/resources/waitfor.sh 127.0.0.1 3306 \
&& go test -race -v -timeout 2m ./...
&& ${GO} test -race -v -timeout 2m ./...
docker stop go-mysql-server

fmt:
golangci-lint run --fix

clean:
go clean -i ./...
${GO} clean -i ./...
@rm -rf ./bin
18 changes: 2 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -9,10 +9,10 @@ A pure go library to handle MySQL network protocol and replication.
## 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`:
```
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.9.0
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.10.0
```

v1.9.0 - is the last tag in repo, feel free to choose what you want.
v1.10.0 - is the last tag in repo, feel free to choose what you want.

## Changelog
This repo uses [Changelog](CHANGELOG.md).
@@ -23,7 +23,6 @@ This repo uses [Changelog](CHANGELOG.md).
* [Incremental dumping](#canal)
* [Client](#client)
* [Fake server](#server)
* [Failover](#failover)
* [database/sql like driver](#driver)

## Replication
@@ -305,7 +304,6 @@ func main() {
}
}
}

```

Another shell
@@ -327,18 +325,6 @@ MySQL [(none)]>
>
> To customize server configurations, use ```NewServer()``` and create connection via ```NewCustomizedConn()```.

## Failover

Failover supports to promote a new master and let replicas replicate from it automatically when the old master was down.

Failover supports MySQL >= 5.6.9 with GTID mode, if you use lower version, e.g, MySQL 5.0 - 5.5, please use [MHA](http://code.google.com/p/mysql-master-ha/) or [orchestrator](https://github.com/outbrain/orchestrator).

At the same time, Failover supports MariaDB >= 10.0.9 with GTID mode too.

Why only GTID? Supporting failover with no GTID mode is very hard, because replicas can not find the proper binlog filename and position with the new master.
Although there are many companies use MySQL 5.0 - 5.5, I think upgrade MySQL to 5.6 or higher is easy.

## Driver

Driver is the package that you can use go-mysql with go database/sql like other drivers. A simple example:
13 changes: 6 additions & 7 deletions canal/canal.go
Original file line number Diff line number Diff line change
@@ -481,18 +481,17 @@ func (c *Canal) prepareSyncer() error {
if strings.Contains(c.cfg.Addr, "/") {
cfg.Host = c.cfg.Addr
} else {
seps := strings.Split(c.cfg.Addr, ":")
if len(seps) != 2 {
return errors.Errorf("invalid mysql addr format %s, must host:port", c.cfg.Addr)
host, port, err := net.SplitHostPort(c.cfg.Addr)
if err != nil {
return errors.Errorf("invalid MySQL address format %s, must host:port", c.cfg.Addr)
}

port, err := strconv.ParseUint(seps[1], 10, 16)
portNumber, err := strconv.ParseUint(port, 10, 16)
if err != nil {
return errors.Trace(err)
}

cfg.Host = seps[0]
cfg.Port = uint16(port)
cfg.Host = host
cfg.Port = uint16(portNumber)
}

c.syncer = replication.NewBinlogSyncer(cfg)
23 changes: 22 additions & 1 deletion canal/canal_test.go
Original file line number Diff line number Diff line change
@@ -16,12 +16,30 @@ import (
)

type canalTestSuite struct {
addr string
suite.Suite
c *Canal
}

type canalTestSuiteOption func(c *canalTestSuite)

func withAddr(addr string) canalTestSuiteOption {
return func(c *canalTestSuite) {
c.addr = addr
}
}

func newCanalTestSuite(opts ...canalTestSuiteOption) *canalTestSuite {
c := new(canalTestSuite)
for _, opt := range opts {
opt(c)
}
return c
}

func TestCanalSuite(t *testing.T) {
suite.Run(t, new(canalTestSuite))
suite.Run(t, newCanalTestSuite())
suite.Run(t, newCanalTestSuite(withAddr(mysql.DEFAULT_IPV6_ADDR)))
}

const (
@@ -37,6 +55,9 @@ const (
func (s *canalTestSuite) SetupSuite() {
cfg := NewDefaultConfig()
cfg.Addr = fmt.Sprintf("%s:%s", *test_util.MysqlHost, *test_util.MysqlPort)
if s.addr != "" {
cfg.Addr = s.addr
}
cfg.User = "root"
cfg.HeartbeatPeriod = 200 * time.Millisecond
cfg.ReadTimeout = 300 * time.Millisecond
2 changes: 1 addition & 1 deletion client/auth.go
Original file line number Diff line number Diff line change
@@ -304,7 +304,7 @@ func (c *Conn) writeAuthHandshake() error {
}

currentSequence := c.Sequence
c.Conn = packet.NewBufferedConn(tlsConn, c.BufferSize)
c.Conn = packet.NewConnWithTimeout(tlsConn, c.ReadTimeout, c.WriteTimeout, c.BufferSize)
c.Sequence = currentSequence
}

7 changes: 7 additions & 0 deletions cmd/go-canal/main.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import (

"github.com/go-mysql-org/go-mysql/canal"
"github.com/go-mysql-org/go-mysql/mysql"
"github.com/pingcap/errors"
)

var (
@@ -41,6 +42,12 @@ var (
func main() {
flag.Parse()

err := mysql.ValidateFlavor(*flavor)
if err != nil {
fmt.Printf("Flavor error: %v\n", errors.ErrorStack(err))
return
}

cfg := canal.NewDefaultConfig()
cfg.Addr = net.JoinHostPort(*host, strconv.Itoa(*port))
cfg.User = *user
21 changes: 14 additions & 7 deletions cmd/go-mysqlbinlog/main.go
Original file line number Diff line number Diff line change
@@ -40,13 +40,20 @@ func main() {
ServerID: 101,
Flavor: *flavor,

Host: *host,
Port: uint16(*port),
User: *user,
Password: *password,
RawModeEnabled: *rawMode,
SemiSyncEnabled: *semiSync,
UseDecimal: true,
Host: *host,
Port: uint16(*port),
User: *user,
Password: *password,
RawModeEnabled: *rawMode,
SemiSyncEnabled: *semiSync,
UseDecimal: true,
MaxReconnectAttempts: 10,
}

err := mysql.ValidateFlavor(*flavor)
if err != nil {
fmt.Printf("Flavor error: %v\n", errors.ErrorStack(err))
return
}

b := replication.NewBinlogSyncer(cfg)
15 changes: 9 additions & 6 deletions cmd/go-mysqldump/main.go
Original file line number Diff line number Diff line change
@@ -15,24 +15,27 @@ var (
addr = flag.String("addr", "127.0.0.1:3306", "MySQL addr")
user = flag.String("user", "root", "MySQL user")
password = flag.String("password", "", "MySQL password")
execution = flag.String("exec", "mysqldump", "mysqldump execution path")
execution = flag.String("exec", "", "mysqldump/mariadb-dump execution path")
output = flag.String("o", "", "dump output, empty for stdout")

dbs = flag.String("dbs", "", "dump databases, separated by comma")
tables = flag.String("tables", "", "dump tables, separated by comma, will overwrite dbs")
tableDB = flag.String("table_db", "", "database for dump tables")
ignoreTables = flag.String("ignore_tables", "", "ignore tables, must be database.table format, separated by comma")
dbs = flag.String("dbs", "", "dump databases, separated by comma")
tables = flag.String("tables", "", "dump tables, separated by comma, will overwrite dbs")
tableDB = flag.String("table_db", "", "database for dump tables")
ignoreTables = flag.String("ignore_tables", "", "ignore tables, must be database.table format, separated by comma")
skipBinlogPos = flag.Bool("skip-binlog-pos", false, "skip fetching binlog position via --master-data/--source-data")
)

func main() {
flag.Parse()

d, err := dump.NewDumper(*execution, *addr, *user, *password)
if err != nil {
fmt.Printf("Create Dumper error %v\n", errors.ErrorStack(err))
fmt.Printf("Create Dumper error: %v\n", errors.ErrorStack(err))
os.Exit(1)
}

d.SkipMasterData(*skipBinlogPos)

if len(*ignoreTables) > 0 {
subs := strings.Split(*ignoreTables, ",")
for _, sub := range subs {
42 changes: 42 additions & 0 deletions cmd/go-mysqlserver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"log"
"net"

"github.com/go-mysql-org/go-mysql/server"
)

func main() {
// Listen for connections on localhost port 4000
l, err := net.Listen("tcp", "127.0.0.1:4000")
if err != nil {
log.Fatal(err)
}

log.Println("Listening on port 4000, connect with 'mysql -h 127.0.0.1 -P 4000 -u root'")

// Accept a new connection once
c, err := l.Accept()
if err != nil {
log.Fatal(err)
}

log.Println("Accepted connection")

// Create a connection with user root and an empty password.
// You can use your own handler to handle command here.
conn, err := server.NewConn(c, "root", "", server.EmptyHandler{})
if err != nil {
log.Fatal(err)
}

log.Println("Registered the connection with the server")

// as long as the client keeps sending commands, keep handling them
for {
if err := conn.HandleCommand(); err != nil {
log.Fatal(err)
}
}
}
Loading