Maint: prefer empty string comparison

This commit is contained in:
Quentin McGaw (desktop)
2021-07-23 17:39:38 +00:00
parent 3c44214d01
commit b23eb8f29d
8 changed files with 10 additions and 11 deletions

View File

@@ -41,7 +41,7 @@ func readCSVPorts(env params.Env, key string) (ports []uint16, err error) {
s, err := env.Get(key)
if err != nil {
return nil, err
} else if len(s) == 0 {
} else if s == "" {
return nil, nil
}
@@ -95,7 +95,7 @@ var (
func readIP(env params.Env, key string) (ip net.IP, err error) {
s, err := env.Get(key)
if len(s) == 0 {
if s == "" {
return nil, nil
} else if err != nil {
return nil, err
@@ -115,7 +115,7 @@ func readPortOrZero(env params.Env, key string) (port uint16, err error) {
return 0, err
}
if len(s) == 0 || s == "0" {
if s == "" || s == "0" {
return 0, nil
}

View File

@@ -65,7 +65,7 @@ func (r *reader) getFromEnvOrSecretFile(envKey string, compulsory bool, retroKey
value = string(b)
value = cleanSuffix(value)
if compulsory && len(value) == 0 {
if compulsory && value == "" {
return "", ErrSecretFileIsEmpty
}

View File

@@ -7,11 +7,11 @@ import (
)
func (h *handler) isAuthorized(responseWriter http.ResponseWriter, request *http.Request) (authorized bool) {
if len(h.username) == 0 || (request.Method != "CONNECT" && !request.URL.IsAbs()) {
if h.username == "" || (request.Method != "CONNECT" && !request.URL.IsAbs()) {
return true
}
basicAuth := request.Header.Get("Proxy-Authorization")
if len(basicAuth) == 0 {
if basicAuth == "" {
h.logger.Info("Proxy-Authorization header not found from " + request.RemoteAddr)
responseWriter.Header().Set("Proxy-Authenticate", `Basic realm="Access to Gluetun over HTTP"`)
responseWriter.WriteHeader(http.StatusProxyAuthRequired)

View File

@@ -24,7 +24,7 @@ func (l *looper) collectLines(stdout, stderr <-chan string, done chan<- struct{}
return
}
line, level := processLogLine(line)
if len(line) == 0 {
if line == "" {
continue // filtered out
}
if errLine {

View File

@@ -76,7 +76,7 @@ func (r *routing) DefaultIP() (ip net.IP, err error) {
defaultLinkName = link.Attrs().Name
}
}
if len(defaultLinkName) == 0 {
if defaultLinkName == "" {
return nil, fmt.Errorf("%w: in %d route(s)", ErrLinkDefaultNotFound, len(routes))
}

View File

@@ -76,7 +76,7 @@ func extractRemoteHosts(content []byte, rejectIP, rejectDomain bool) (hosts []st
continue
}
fields := strings.Fields(line)
if len(fields) == 1 || len(fields[1]) == 0 {
if len(fields) == 1 || fields[1] == "" {
continue
}
host := fields[1]

View File

@@ -35,7 +35,7 @@ type updater struct {
func New(settings configuration.Updater, httpClient *http.Client,
currentServers models.AllServers, logger logging.Logger) Updater {
if len(settings.DNSAddress) == 0 {
if settings.DNSAddress == "" {
settings.DNSAddress = "1.1.1.1"
}
unzipper := unzip.New(httpClient)

View File

@@ -14,7 +14,6 @@
## Code
- Change empty string comparison from `len(s) == 0` to `s == ""`
- Use `github.com/qdm12/ddns-updater/pkg/publicip`
- Change firewall debug logs to use `logger.Debug` instead of `fmt.Println`