replace
len(c.TiDBCAPath) != 0
with c.TiDBCAPath != ""
781
782// ToTiDBTLSConfig generates tls config for connecting to TiDB, used by tidb-dashboard.
783func (c *DashboardConfig) ToTiDBTLSConfig() (*tls.Config, error) {
784 if (len(c.TiDBCertPath) != 0 && len(c.TiDBKeyPath) != 0) || len(c.TiDBCAPath) != 0 {785 tlsInfo := transport.TLSInfo{
786 CertFile: c.TiDBCertPath,
787 KeyFile: c.TiDBKeyPath,
replace
len(c.TiDBKeyPath) != 0
with c.TiDBKeyPath != ""
781
782// ToTiDBTLSConfig generates tls config for connecting to TiDB, used by tidb-dashboard.
783func (c *DashboardConfig) ToTiDBTLSConfig() (*tls.Config, error) {
784 if (len(c.TiDBCertPath) != 0 && len(c.TiDBKeyPath) != 0) || len(c.TiDBCAPath) != 0 {785 tlsInfo := transport.TLSInfo{
786 CertFile: c.TiDBCertPath,
787 KeyFile: c.TiDBKeyPath,
replace
len(c.TiDBCertPath) != 0
with c.TiDBCertPath != ""
781
782// ToTiDBTLSConfig generates tls config for connecting to TiDB, used by tidb-dashboard.
783func (c *DashboardConfig) ToTiDBTLSConfig() (*tls.Config, error) {
784 if (len(c.TiDBCertPath) != 0 && len(c.TiDBKeyPath) != 0) || len(c.TiDBCAPath) != 0 {785 tlsInfo := transport.TLSInfo{
786 CertFile: c.TiDBCertPath,
787 KeyFile: c.TiDBKeyPath,
replace
len(c.Security.CAPath) != 0
with c.Security.CAPath != ""
733 cfg.ClientTLSInfo.CertFile = c.Security.CertPath
734 cfg.ClientTLSInfo.KeyFile = c.Security.KeyPath
735 // Client no need to set the CN. (cfg.ClientTLSInfo.AllowedCN = allowedCN)
736 cfg.PeerTLSInfo.ClientCertAuth = len(c.Security.CAPath) != 0737 cfg.PeerTLSInfo.TrustedCAFile = c.Security.CAPath
738 cfg.PeerTLSInfo.CertFile = c.Security.CertPath
739 cfg.PeerTLSInfo.KeyFile = c.Security.KeyPath
replace
len(c.Security.CAPath) != 0
with c.Security.CAPath != ""
728 if serr != nil {
729 return nil, serr
730 }
731 cfg.ClientTLSInfo.ClientCertAuth = len(c.Security.CAPath) != 0732 cfg.ClientTLSInfo.TrustedCAFile = c.Security.CAPath
733 cfg.ClientTLSInfo.CertFile = c.Security.CertPath
734 cfg.ClientTLSInfo.KeyFile = c.Security.KeyPath
replace
len(c.Log.Format) == 0
with c.Log.Format == ""
469
470 c.Security.Encryption.Adjust()
471
472 if len(c.Log.Format) == 0 {473 c.Log.Format = defaultLogFormat
474 }
475
replace
len(c.InitialCluster) == 0
with c.InitialCluster == ""
381 configutil.AdjustString(&c.AdvertisePeerUrls, c.PeerUrls)
382 configutil.AdjustDuration(&c.Metric.PushInterval, defaultMetricsPushInterval)
383
384 if len(c.InitialCluster) == 0 {385 // The advertise peer urls may be http://127.0.0.1:2380,http://127.0.0.1:2381
386 // so the initial cluster is pd=http://127.0.0.1:2380,pd=http://127.0.0.1:2381
387 items := strings.Split(c.AdvertisePeerUrls, ",")
Description
It is not recommended to use len
for empty string test.
A string can be tested for its emptiness either by treating it as a slice and calculating the length of the slice, or by treating it as a string and directly comparing the value. While both produce identical code when compiled, it makes more sense to treat a string as itself, than a slice, for the sake of comparison of values.
Bad practice
len(s) == 0
Recommended
s == ""
The recommended practice is considered more idiomatic in Go.