1
0
mirror of https://github.com/TwiN/gatus.git synced 2026-02-12 23:55:18 +00:00

refactor: Simplify and modernize loops (#1522)

* refactor: Simplify loops

* refactor: Modernize loops using range over int

---------

Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
PythonGermany
2026-02-09 01:08:59 +01:00
committed by GitHub
parent e5b4e0d381
commit f09d959c97
17 changed files with 45 additions and 78 deletions

View File

@@ -216,7 +216,7 @@ func sanitizeAndResolveNumericalWithContext(list []string, result *Result, conte
func prettifyNumericalParameters(parameters []string, resolvedParameters []int64, operator string) string {
resolvedStrings := make([]string, 2)
for i := 0; i < 2; i++ {
for i := range 2 {
// Check if the parameter is a certificate or domain expiration placeholder
if parameters[i] == CertificateExpirationPlaceholder || parameters[i] == DomainExpirationPlaceholder {
// Format as duration string (convert milliseconds back to duration)

View File

@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"math/rand"
"net"
"net/http"
@@ -489,9 +490,7 @@ func (e *Endpoint) call(result *Result) {
} else if endpointType == TypeWS {
wsHeaders := map[string]string{}
if e.Headers != nil {
for k, v := range e.Headers {
wsHeaders[k] = v
}
maps.Copy(wsHeaders, e.Headers)
}
if !hasHeader(wsHeaders, UserAgentHeader) {
wsHeaders[UserAgentHeader] = GatusUserAgent

View File

@@ -1,6 +1,7 @@
package endpoint
import (
"slices"
"time"
)
@@ -66,11 +67,7 @@ type Result struct {
// AddError adds an error to the result's list of errors.
// It also ensures that there are no duplicates.
func (r *Result) AddError(error string) {
for _, resultError := range r.Errors {
if resultError == error {
// If the error already exists, don't add it
return
}
if !slices.Contains(r.Errors, error) {
r.Errors = append(r.Errors, error+"")
}
r.Errors = append(r.Errors, error+"")
}