Add support for Unix domain sockets.

This adds a new configuration option, socket-path, instead of using
host.
This commit is contained in:
Alex Jaspersen 2020-05-17 05:00:04 +00:00
parent c0b74f298a
commit 3468a8cb8a
4 changed files with 8 additions and 1 deletions

View file

@ -88,7 +88,9 @@ func (mysql *MySQL) getExpireTime() (expireTime time.Duration) {
func (m *MySQL) Open() (err error) {
var address string
if m.config.Port != 0 {
if m.config.SocketPath != "" {
address = fmt.Sprintf("unix(%s)", m.config.SocketPath)
} else if m.config.Port != 0 {
address = fmt.Sprintf("tcp(%s:%d)", m.config.Host, m.config.Port)
}