Documentation ¶
Index ¶
- Constants
- Variables
- func DeregisterTLSConfig(key string)
- func NewXconfigFromConfig(cfg *config) *xconfig
- func RegisterDial(net string, dial DialFunc)
- func RegisterTLSConfig(key string, config *tls.Config) error
- func SetLogger(logger Logger) error
- type DialFunc
- type Logger
- type MySQL41
- type MySQLWarning
- type MySQLWarnings
- type NullTime
- type ServerCapabilities
- func (sc ServerCapabilities) AddArrayString(name string, values []string) error
- func (sc ServerCapabilities) AddScalarBool(name string, value bool) error
- func (sc ServerCapabilities) AddScalarString(name string, value string) error
- func (sc ServerCapabilities) Exists(name string) bool
- func (sc ServerCapabilities) Values(name string) Values
- type Values
- type XDriver
Constants ¶
const ( // CapabilityString is a string CapabilityString capabilityType = iota // CapabilityBool is a boolean CapabilityBool )
Variables ¶
var ( ErrInvalidConn = errors.New("Invalid Connection") ErrMalformPkt = errors.New("Malformed Packet") ErrNoTLS = errors.New("TLS encryption requested but server does not support TLS") ErrOldPassword = errors.New("This user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords") ErrCleartextPassword = errors.New("This user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN.") ErrUnknownPlugin = errors.New("The authentication plugin is not supported.") ErrOldProtocol = errors.New("MySQL-Server does not support required Protocol 41+") ErrPktSync = errors.New("Commands out of sync. You can't run this command now") ErrPktSyncMul = errors.New("Commands out of sync. Did you run multiple statements at once?") ErrPktTooLarge = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.") ErrBusyBuffer = errors.New("Busy buffer") )
Various errors the driver might return. Can change between driver versions.
Functions ¶
func DeregisterTLSConfig ¶
func DeregisterTLSConfig(key string)
DeregisterTLSConfig removes the tls.Config associated with key.
func NewXconfigFromConfig ¶
func NewXconfigFromConfig(cfg *config) *xconfig
func RegisterDial ¶
RegisterDial registers a custom dial function. It can then be used by the network address mynet(addr), where mynet is the registered new network. addr is passed as a parameter to the dial function.
func RegisterTLSConfig ¶
RegisterTLSConfig registers a custom tls.Config to be used with sql.Open. Use the key as a value in the DSN where tls=value.
rootCertPool := x509.NewCertPool() pem, err := ioutil.ReadFile("/path/ca-cert.pem") if err != nil { log.Fatal(err) } if ok := rootCertPool.AppendCertsFromPEM(pem); !ok { log.Fatal("Failed to append PEM.") } clientCert := make([]tls.Certificate, 0, 1) certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem") if err != nil { log.Fatal(err) } clientCert = append(clientCert, certs) mysql.RegisterTLSConfig("custom", &tls.Config{ RootCAs: rootCertPool, Certificates: clientCert, }) db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
Types ¶
type DialFunc ¶
DialFunc is a function which can be used to establish the network connection. Custom dial functions must be registered with RegisterDial
type Logger ¶
type Logger interface {
Print(v ...interface{})
}
Logger is used to log critical error messages.
type MySQL41 ¶
type MySQL41 struct {
// contains filtered or unexported fields
}
MySQL41 manages the MySQL41 authentication protocol
func NewMySQL41 ¶
NewMySQL41 returns a pointer to an initialised MySQL41 struct
func (*MySQL41) GetInitialAuthData ¶
GetInitialAuthData returns any initial authentication data
func (*MySQL41) GetNextAuthData ¶
GetNextAuthData returns data db + name + encrypted hash
type MySQLWarning ¶
MySQLWarning is an error type which represents a single MySQL warning. Warnings are returned in groups only. See MySQLWarnings
type MySQLWarnings ¶
type MySQLWarnings []MySQLWarning
MySQLWarnings is an error type which represents a group of one or more MySQL warnings
func (MySQLWarnings) Error ¶
func (mws MySQLWarnings) Error() string
type NullTime ¶
NullTime represents a time.Time that may be NULL. NullTime implements the Scanner interface so it can be used as a scan destination:
var nt NullTime err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt) ... if nt.Valid { // use nt.Time } else { // NULL value }
This NullTime implementation is not driver-specific
type ServerCapabilities ¶
ServerCapabilities is a named map of capability values
func NewServerCapabilities ¶
func NewServerCapabilities() ServerCapabilities
NewServerCapabilities returns a structure containing the named capabilities of the server
func (ServerCapabilities) AddArrayString ¶
func (sc ServerCapabilities) AddArrayString(name string, values []string) error
AddArrayString adds the given array of strings to the named capability
func (ServerCapabilities) AddScalarBool ¶
func (sc ServerCapabilities) AddScalarBool(name string, value bool) error
AddScalarBool adds the given boolean value to the named capability
func (ServerCapabilities) AddScalarString ¶
func (sc ServerCapabilities) AddScalarString(name string, value string) error
AddScalarString adds the given string value to the named capability
func (ServerCapabilities) Exists ¶
func (sc ServerCapabilities) Exists(name string) bool
Exists returns true if the named capability exists
func (ServerCapabilities) Values ¶
func (sc ServerCapabilities) Values(name string) Values
Values returns the named Values