2016-03-30 13:43:40 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 GitHub Inc.
|
2016-05-16 09:09:17 +00:00
|
|
|
See https://github.com/github/gh-ost/blob/master/LICENSE
|
2016-03-30 13:43:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package mysql
|
|
|
|
|
2016-04-04 13:29:02 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2016-03-30 13:43:40 +00:00
|
|
|
// ConnectionConfig is the minimal configuration required to connect to a MySQL server
|
|
|
|
type ConnectionConfig struct {
|
2016-04-04 13:29:02 +00:00
|
|
|
Key InstanceKey
|
2016-03-30 13:43:40 +00:00
|
|
|
User string
|
|
|
|
Password string
|
|
|
|
}
|
2016-04-04 13:29:02 +00:00
|
|
|
|
|
|
|
func NewConnectionConfig() *ConnectionConfig {
|
|
|
|
config := &ConnectionConfig{
|
|
|
|
Key: InstanceKey{},
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *ConnectionConfig) Duplicate() *ConnectionConfig {
|
|
|
|
config := &ConnectionConfig{
|
|
|
|
Key: InstanceKey{
|
|
|
|
Hostname: this.Key.Hostname,
|
|
|
|
Port: this.Key.Port,
|
|
|
|
},
|
|
|
|
User: this.User,
|
|
|
|
Password: this.Password,
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *ConnectionConfig) String() string {
|
|
|
|
return fmt.Sprintf("%s, user=%s", this.Key.DisplayString(), this.User)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *ConnectionConfig) Equals(other *ConnectionConfig) bool {
|
|
|
|
return this.Key.Equals(&other.Key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *ConnectionConfig) GetDBUri(databaseName string) string {
|
|
|
|
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", this.User, this.Password, this.Key.Hostname, this.Key.Port, databaseName)
|
|
|
|
}
|