Documentation ¶
Index ¶
- Constants
- Variables
- type Buffer
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Len() int
- func (b *Buffer) ReadByte() (byte, error)
- func (b *Buffer) ReadBytes(n int) ([]byte, error)
- func (b *Buffer) ReadLenencInt() (uint64, error)
- func (b *Buffer) ReadLenencString() (string, error)
- func (b *Buffer) ReadStringNull() (string, error)
- func (b *Buffer) ReadUint16() (uint16, error)
- func (b *Buffer) ReadUint24() (uint32, error)
- func (b *Buffer) ReadUint32() (uint32, error)
- func (b *Buffer) ReadUint64() (uint64, error)
- func (b *Buffer) Skip(n int) error
- func (b *Buffer) WriteByte(by byte)
- func (b *Buffer) WriteBytes(bys []byte)
- func (b *Buffer) WriteLenencInt(n uint64)
- func (b *Buffer) WriteLenencString(s string)
- func (b *Buffer) WriteStringNull(s string)
- func (b *Buffer) WriteUint16(n uint16)
- func (b *Buffer) WriteUint24(n uint32)
- func (b *Buffer) WriteUint32(n uint32)
- func (b *Buffer) WriteUint64(n uint64)
- type Compressor
- type Conn
- func (p *Conn) Close()
- func (c *Conn) EnableCompression()
- func (c *Conn) Flush() error
- func (p *Conn) RawConn() net.Conn
- func (c *Conn) ReadPacket(b *bytes.Buffer) error
- func (c *Conn) ReadPartialPacket(b *bytes.Buffer) (n int, err error)
- func (c *Conn) RecvPacket(pkg Packet) error
- func (c *Conn) SendPacket(pkt Packet) error
- func (c *Conn) SetMaxAllowedPacket(maxAllowedPacket uint64)
- func (c *Conn) SetRawConn(conn net.Conn)
- func (c *Conn) SetReadTimeout(timeout time.Duration)
- func (c *Conn) SetResetOption(opt uint8)
- func (c *Conn) WritePacket(data []byte) error
- type Err
- type Handshake
- type HandshakeResponse
- type Packet
- type WriteFlusher
Constants ¶
const ( SeqResetNone uint8 = 0 SeqResetOnRead uint8 = 1 SeqResetOnWrite uint8 = 2 SeqResetBoth uint8 = 3 )
Options to determine when the sequence number should be reset.
const ( DefaultHandshakeVersion = 10 DefaultCollationID = 46 DefaultCapability = ClientLongPassword | ClientLongFlag | ClientConnectWithDB | ClientProtocol41 | ClientTransactions | ClientSecureConnection | ClientFoundRows | ClientMultiStatements | ClientMultiResults | ClientLocalFiles | ClientConnectAttrs | ClientPluginAuth | ClientInteractive )
Packet constants.
const ( HeaderOK = 0x00 HeaderEOF = 0xFE HeaderErr = 0xFF )
OK packet constants.
const ( ServerStatusInTrans uint16 = 0x0001 ServerStatusAutocommit uint16 = 0x0002 ServerMoreResultsExists uint16 = 0x0008 ServerStatusNoGoodIndexUsed uint16 = 0x0010 ServerStatusNoIndexUsed uint16 = 0x0020 ServerStatusCursorExists uint16 = 0x0040 ServerStatusLastRowSend uint16 = 0x0080 ServerStatusDBDropped uint16 = 0x0100 ServerStatusNoBackslashEscaped uint16 = 0x0200 ServerStatusMetadataChanged uint16 = 0x0400 ServerStatusWasSlow uint16 = 0x0800 ServerPSOutParams uint16 = 0x1000 ServerStatusInTransReadonly uint16 = 0x2000 ServerSessionStateChanged uint16 = 0x4000 )
Server information.
const ( ClientLongPassword uint32 = 1 << iota ClientFoundRows ClientLongFlag ClientConnectWithDB ClientNoSchema ClientCompress ClientODBC ClientLocalFiles ClientIgnoreSpace ClientProtocol41 ClientInteractive ClientSSL ClientIgnoreSigpipe ClientTransactions ClientReserved ClientSecureConnection ClientMultiStatements ClientMultiResults ClientPSMultiResults ClientPluginAuth ClientConnectAttrs ClientPluginAuthLenencClientData ClientCanHandleExpiredPasswords ClientSessionTrack ClientDeprecateEOF )
Client information.
const ( AuthInvalidMethod = "invalid_dummy_method" AuthNativePassword = "mysql_native_password" // #nosec G101 AuthCachingSha2Password = "caching_sha2_password" // #nosec G101 AuthSocket = "auth_socket" )
Auth name information.
const ( ErrCodeUnknown = 1105 UnknownState = "08S01" )
const (
// MaxPayloadLen is the max packet payload length.
MaxPayloadLen = 1<<24 - 1
)
Variables ¶
var ( ErrBadConn = errors.New("connection was bad") ErrMalformPacket = errors.New("malform packet") )
Portable analogs of some common call errors.
var CollationNames = map[string]uint8{}/* 220 elements not displayed */
CollationNames maps MySQL collation name to its ID
var Collations = map[uint8]string{}/* 220 elements not displayed */
Collations maps MySQL collation ID to its name.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer wraps bytes.Buffer for read/write mysql data types.
func (*Buffer) Len ¶
Len returns the number of bytes written to the buffer or left to read from the buffer
func (*Buffer) ReadLenencInt ¶
ReadLenencInt reads a lenenc int.
func (*Buffer) ReadLenencString ¶
ReadLenencString reads a lenenc string.
func (*Buffer) ReadStringNull ¶
ReadStringNull reads a string followed by a null byte.
func (*Buffer) ReadUint16 ¶
ReadUint16 reads a uint16.
func (*Buffer) ReadUint24 ¶
ReadUint24 reads a uint24.
func (*Buffer) ReadUint32 ¶
ReadUint32 reads a uint32.
func (*Buffer) ReadUint64 ¶
ReadUint64 reads a uint64.
func (*Buffer) WriteLenencInt ¶
WriteLenencInt writes a lenenc int.
func (*Buffer) WriteLenencString ¶
WriteLenencString writes a lenenc string.
func (*Buffer) WriteStringNull ¶
WriteString writes a string followed by a null byte.
type Compressor ¶
type Compressor struct {
// contains filtered or unexported fields
}
Compressor wraps a Reader and a WriteFlusher for compression.
func NewCompressor ¶
func NewCompressor(r io.Reader, w WriteFlusher) *Compressor
NewCompressor creates a new Compressor.
func (*Compressor) Flush ¶
func (c *Compressor) Flush() error
Flush compress then flush the data to the underlying writer.
func (*Compressor) Read ¶
func (c *Compressor) Read(p []byte) (int, error)
Read reads data from the underlying reader.
func (*Compressor) SetResetOption ¶
func (c *Compressor) SetResetOption(opt uint8)
SetResetOption marks the sequence to be reset on next read or write.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn wraps net.Conn for data read/write. MySQL Packets: https://dev.mysql.com/doc/internals/en/mysql-packet.html
func (*Conn) EnableCompression ¶
func (c *Conn) EnableCompression()
EnableCompression wraps the underlying reader and writer to support compression.
func (*Conn) ReadPacket ¶
ReadPacket reads a complete MySQL packet.
func (*Conn) ReadPartialPacket ¶
ReadpartialPacket reads a MySQL wire packet. It may be part of a larger packet.
func (*Conn) RecvPacket ¶
RecvPacket receives a MySQL packet.
func (*Conn) SendPacket ¶
SendPacket sends a MySQL packet.
func (*Conn) SetMaxAllowedPacket ¶
SetMaxAllowedPacket sets the maximum packet size.
func (*Conn) SetRawConn ¶
SetRawConn resets the underlying net.Conn. Used for upgrading to TLS.
func (*Conn) SetReadTimeout ¶
SetReadTimeout sets the read timeout for the connection.
func (*Conn) SetResetOption ¶
SetResetOption marks the connection to reset sequence on next read/write.
type Handshake ¶
type Handshake struct { ProtocolVersion uint8 ServerVersion string ConnectionID uint32 AuthPluginData []byte Capability uint32 CharacterSet uint8 StatusFlags uint16 AuthPluginName string }
Handshake is the initial handshake packet sent from server to client.
type HandshakeResponse ¶
type HandshakeResponse struct { Capability uint32 MaxPacketSize uint32 CharacterSet byte UserName string DBName string Auth []byte AuthPlugin string Attrs map[string]string }
HandshakerResponse is the initial handshake response from the client.
func (*HandshakeResponse) Read ¶
func (s *HandshakeResponse) Read(b *Buffer) error
Read reads the handshake response from the buffer.
func (*HandshakeResponse) Write ¶
func (s *HandshakeResponse) Write(b *Buffer)
Write writes the handshake response to the buffer.
type WriteFlusher ¶
WriterFlusher represents a buffered writer. (like bufio.Writer)