This section describes how to implement your MySQL-compatible server using the go-mysql, and see Examples about the sample implementation.
The go-mysql offers a core server, mysql.Server, and so inherit the core server in your instance as the following.
import (
"github.com/cybergarage/go-mysql/mysql"
)
type MyServer struct {
*mysql.Server
}
func NewMyServer() *MyServer {
return &MyServer{
Server: mysql.NewServer(),
}
}
To handle queries to the your server, prepare a query handler according to mysql.QueryExecutor interface.
func NewMyServer() *MyServer {
myserver := &MyServer{
Server: mysql.NewServer(),
}
Myserver.SetQueryExecutor(myserver)
return myserver
}
func (server *MyServer) Insert(*Conn, *query.Insert) (*Result, error) {
.....
}
....
The go-mysql offers the stub query executor, mysql.BaseExecutor which returns a success status for any query requests. To inheriting the stub executor, you can start to implement only minimum query handle functions such as INSERT and SELECT.
After implementing the query handler, start your server using mysql.Server::Start().
server := NewServer()
err := server.Start()
if err != nil {
t.Error(err)
return
}
defer server.Stop()
....