Skip to content

Commit 1f3abe6

Browse files
committed
Use NewConfig() to initialize mysql.Config with correct defaults
1 parent 74e2f41 commit 1f3abe6

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

proxy/dialers/mysql/hook.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ func init() {
3838
// The returned *sql.DB may be valid even if there's also an error returned
3939
// (e.g. if there was a transient connection error).
4040
func Dial(instance, user string) (*sql.DB, error) {
41-
return DialCfg(&mysql.Config{
42-
User: user,
43-
Addr: instance,
44-
// Set in DialCfg:
45-
// Net: "cloudsql",
46-
})
41+
cfg := mysql.NewConfig()
42+
cfg.User = user
43+
cfg.Addr = instance
44+
return DialCfg(cfg)
4745
}
4846

4947
// DialPassword is similar to Dial, but allows you to specify a password.
@@ -53,26 +51,24 @@ func Dial(instance, user string) (*sql.DB, error) {
5351
// information, see:
5452
// https://cloud.google.com/sql/docs/sql-proxy#user
5553
func DialPassword(instance, user, password string) (*sql.DB, error) {
56-
return DialCfg(&mysql.Config{
57-
User: user,
58-
Passwd: password,
59-
Addr: instance,
60-
// Set in DialCfg:
61-
// Net: "cloudsql",
62-
})
54+
cfg := mysql.NewConfig()
55+
cfg.User = user
56+
cfg.Passwd = password
57+
cfg.Addr = instance
58+
return DialCfg(cfg)
6359
}
6460

6561
// Cfg returns the effective *mysql.Config to represent connectivity to the
6662
// provided instance via the given user and password. The config can be
6763
// modified and passed to DialCfg to connect. If you don't modify the returned
6864
// config before dialing, consider using Dial or DialPassword.
6965
func Cfg(instance, user, password string) *mysql.Config {
70-
return &mysql.Config{
71-
Addr: instance,
72-
User: user,
73-
Passwd: password,
74-
Net: "cloudsql",
75-
}
66+
cfg := mysql.NewConfig()
67+
cfg.User = user
68+
cfg.Passwd = password
69+
cfg.Addr = instance
70+
cfg.Net = "cloudsql"
71+
return cfg
7672
}
7773

7874
// DialCfg opens up a SQL connection to a Cloud SQL Instance specified by the

0 commit comments

Comments
 (0)