mysql

package
v1.0.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Speaks 4.1 protocol.
	ClientProtocol41 = 0x00000200
	// Can do 4.1 authentication.
	ClientPluginAuth = 0x00008000
)

Capability flags.

View Source
const (
	UTF8GeneralCI = 0x21
)

Character sets.

Variables

View Source
var ComQUIT = []byte{1, 0, 0, 0, 1}

ComQUIT is a complete MySQL packet of COM_QUIT. https://dev.mysql.com/doc/internals/en/com-quit.html

Functions

func NewHealthCheckPacket

func NewHealthCheckPacket(username string) []byte

NewHealthCheckPacket creates MySQL packet for health checking with given username. NOTE: The returned bytes contains two MySQL packets in the following order: 1. HandshakeResponse 2. Command QUIT

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker does health checking with MySQL protocol. It does a login and expecting an reply.

func NewChecker

func NewChecker(config *hc.MySQLChecker) (*Checker, error)

NewChecker creates MySQLChecker.

func (*Checker) Check

func (c *Checker) Check(addr string, timeout time.Duration) error

Check checks given host with timeout.

type HandshakeResponse

type HandshakeResponse struct {
	CapabilityFlags uint32
	MaxPacketSize   uint32
	CharacterSet    uint8
	Reserved        [23]uint8
	Username        string
	// AuthResponse should be a string but password is not used yet, so it will always be a \0.
	AuthResponse uint8
}

HandshakeResponse is composed as follows: https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse 4 capability flags, CLIENT_PROTOCOL_41 always set 4 max-packet size 1 character set string[23] reserved (all [0]) string[NUL] username

if capabilities & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA {
  lenenc-int     length of auth-response
  string[n]      auth-response
} else if capabilities & CLIENT_SECURE_CONNECTION {
  1              length of auth-response
  string[n]      auth-response
} else {
  string[NUL]    auth-response
}
if capabilities & CLIENT_CONNECT_WITH_DB {
  string[NUL]    database
}
if capabilities & CLIENT_PLUGIN_AUTH {
  string[NUL]    auth plugin name
}
if capabilities & CLIENT_CONNECT_ATTRS {
  lenenc-int     length of all key-values
  lenenc-str     key
  lenenc-str     value
  if-more data in 'length of all key-values', more keys and value pairs
}

func (*HandshakeResponse) Bytes

func (r *HandshakeResponse) Bytes() []byte

Bytes returns the payload as bytes.

type Header struct {
	PayloadLen [3]uint8
	SequenceID uint8
}

Header maps the header of a MySQL packet. https://dev.mysql.com/doc/internals/en/mysql-packet.html

func NewMySQLHeaderFromReader

func NewMySQLHeaderFromReader(reader io.Reader) (Header, error)

NewMySQLHeaderFromReader reads a MySQLHeader from reader.

func (*Header) PayloadLength

func (h *Header) PayloadLength() int

PayloadLength returns length of payload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL