MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / Connect

Function Connect

IceFireDB-SQLProxy/pkg/mysql/client/conn.go:54–89  ·  view source on GitHub ↗

Connect to a MySQL server, addr can be ip:port, or a unix socket domain like /var/sock. Accepts a series of configuration functions as a variadic argument.

(addr string, user string, password string, dbName string, options ...func(*Conn))

Source from the content-addressed store, hash-verified

52// Connect to a MySQL server, addr can be ip:port, or a unix socket domain like /var/sock.
53// Accepts a series of configuration functions as a variadic argument.
54func Connect(addr string, user string, password string, dbName string, options ...func(*Conn)) (*Conn, error) {
55 proto := getNetProto(addr)
56
57 c := new(Conn)
58
59 var err error
60 conn, err := net.DialTimeout(proto, addr, 10*time.Second)
61 if err != nil {
62 return nil, errors.Trace(err)
63 }
64
65 if c.tlsConfig != nil {
66 c.Conn = packet.NewTLSConn(conn)
67 } else {
68 c.Conn = packet.NewConn(conn)
69 }
70
71 c.user = user
72 c.password = password
73 c.db = dbName
74 c.proto = proto
75
76 // use default charset here, utf-8
77 c.charset = DEFAULT_CHARSET
78
79 // Apply configuration functions.
80 for i := range options {
81 options[i](c)
82 }
83
84 if err = c.handshake(); err != nil {
85 return nil, errors.Trace(err)
86 }
87
88 return c, nil
89}
90
91func (c *Conn) handshake() error {
92 var err error

Callers 1

NewPoolFunction · 0.70

Calls 4

NewTLSConnFunction · 0.92
NewConnFunction · 0.92
getNetProtoFunction · 0.70
handshakeMethod · 0.45

Tested by

no test coverage detected