mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-06 16:33:02 +00:00
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:
1 parent
4c93d36d49
commit
0401a91ef4
26 files changed
+38
-39
No files matched your search
@@ -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' {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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] != '/' {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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] != '/' {
|
||||
|
||||
Reference in new issue
Block a user