Some code improvements

* Rewrite empty string checks more idiomatically.
* Change strings.ToLower comparisons to strings.EqualFold.
* Rewrite switch statement with only one case as if.
This commit is contained in:
Kirill Motkov committed 2019-06-28 17:53:44 +03:00
1 parent 4c93d36d49
commit 0401a91ef4
26 files changed
+38 -39

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ const protocolName = "domainsocket"
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
path := c.Path
if len(path) == 0 {
if path == "" {
return nil, newError("empty domain socket path")
}
if c.Abstract && path[0] != '\x00' {
+1 -1
View File
@@ -57,7 +57,7 @@ func (v *RequestConfig) GetFullVersion() string {
func (v *ResponseConfig) HasHeader(header string) bool {
cHeader := strings.ToLower(header)
for _, tHeader := range v.Header {
if strings.ToLower(tHeader.Name) == cHeader {
if strings.EqualFold(tHeader.Name, cHeader) {
return true
}
}
+1 -1
View File
@@ -33,7 +33,7 @@ func (c *Config) getRandomHost() string {
}
func (c *Config) getNormalizedPath() string {
if len(c.Path) == 0 {
if c.Path == "" {
return "/"
}
if c.Path[0] != '/' {
+1 -1
View File
@@ -236,7 +236,7 @@ type Option func(*tls.Config)
// WithDestination sets the server name in TLS config.
func WithDestination(dest net.Destination) Option {
return func(config *tls.Config) {
if dest.Address.Family().IsDomain() && len(config.ServerName) == 0 {
if dest.Address.Family().IsDomain() && config.ServerName == "" {
config.ServerName = dest.Address.Domain()
}
}
+1 -1
View File
@@ -33,7 +33,7 @@ func (c *conn) HandshakeAddress() net.Address {
return nil
}
state := c.Conn.ConnectionState()
if len(state.ServerName) == 0 {
if state.ServerName == "" {
return nil
}
return net.ParseAddress(state.ServerName)
+1 -1
View File
@@ -13,7 +13,7 @@ const protocolName = "websocket"
func (c *Config) GetNormalizedPath() string {
path := c.Path
if len(path) == 0 {
if path == "" {
return "/"
}
if path[0] != '/' {