MCPcopy Create free account
hub / github.com/Shopify/ghostferry / MySQLConfig

Method MySQLConfig

config.go:84–129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

82}
83
84func (c *DatabaseConfig) MySQLConfig() (*mysql.Config, error) {
85 var addr string
86
87 if c.Net == "unix" {
88 addr = c.Host
89 } else {
90 addr = fmt.Sprintf("%s:%d", c.Host, c.Port)
91 }
92
93 cfg := &mysql.Config{
94 User: c.User,
95 Passwd: c.Pass,
96 Net: c.Net,
97 Addr: addr,
98 Collation: c.Collation,
99 Params: c.Params,
100 AllowNativePasswords: true,
101 MultiStatements: true,
102 }
103
104 if c.ReadTimeout != 0 {
105 cfg.ReadTimeout = time.Duration(c.ReadTimeout) * time.Second
106 }
107
108 if c.WriteTimeout != 0 {
109 cfg.WriteTimeout = time.Duration(c.WriteTimeout) * time.Second
110 }
111
112 if c.TLS != nil {
113 tlsConfig, err := c.TLS.BuildConfig()
114 if err != nil {
115 return nil, fmt.Errorf("failed to build TLS config: %v", err)
116 }
117
118 cfgName := fmt.Sprintf("%s@%s:%d", c.User, c.Host, c.Port)
119
120 err = mysql.RegisterTLSConfig(cfgName, tlsConfig)
121 if err != nil {
122 return nil, fmt.Errorf("failed to register TLS config: %v", err)
123 }
124
125 cfg.TLSConfig = cfgName
126 }
127
128 return cfg, nil
129}
130
131func (c *DatabaseConfig) Validate() error {
132 if c.Host == "" {

Callers 6

SqlDBMethod · 0.95
TestTcpNetMysqlConfigMethod · 0.80
SetupTestMethod · 0.80
SetupTestMethod · 0.80

Calls 2

BuildConfigMethod · 0.80
ErrorfMethod · 0.65

Tested by 5

TestTcpNetMysqlConfigMethod · 0.64
SetupTestMethod · 0.64
SetupTestMethod · 0.64