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
2019-06-28 17:53:44 +03:00
parent 4c93d36d49
commit 0401a91ef4
26 changed files with 38 additions and 39 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ import (
// ParseXForwardedFor parses X-Forwarded-For header in http headers, and return the IP list in it.
func ParseXForwardedFor(header http.Header) []net.Address {
xff := header.Get("X-Forwarded-For")
if len(xff) == 0 {
if xff == "" {
return nil
}
list := strings.Split(xff, ",")
@@ -38,7 +38,7 @@ func RemoveHopByHopHeaders(header http.Header) {
connections := header.Get("Connection")
header.Del("Connection")
if len(connections) == 0 {
if connections == "" {
return
}
for _, h := range strings.Split(connections, ",") {
+1 -1
View File
@@ -44,7 +44,7 @@ var (
func beginWithHTTPMethod(b []byte) error {
for _, m := range &methods {
if len(b) >= len(m) && strings.ToLower(string(b[:len(m)])) == m {
if len(b) >= len(m) && strings.EqualFold(string(b[:len(m)]), m) {
return nil
}
+1 -2
View File
@@ -81,8 +81,7 @@ func ReadClientHello(data []byte, h *SniffHeader) error {
return errNotClientHello
}
switch extension {
case 0x00: /* extensionServerName */
if extension == 0x00 { /* extensionServerName */
d := data[:length]
if len(d) < 2 {
return errNotClientHello
+1 -1
View File
@@ -51,7 +51,7 @@ func (g *DomainMatcherGroup) addMatcher(m domainMatcher, value uint32) {
}
func (g *DomainMatcherGroup) Match(domain string) uint32 {
if len(domain) == 0 {
if domain == "" {
return 0
}