refactor: go fix ftw

This commit is contained in:
2026-02-19 17:37:42 +01:00
parent 9185ffa6b5
commit 85882bae14
21 changed files with 82 additions and 98 deletions

View File

@@ -90,7 +90,7 @@ func TestEmailService_Performance(t *testing.T) {
start := time.Now()
iterations := 1000
for i := 0; i < iterations; i++ {
for range iterations {
service.GenerateVerificationEmailBody(user.Username, "https://example.com/confirm?token=test")
}
duration := time.Since(start)

View File

@@ -8,6 +8,7 @@ import (
"net"
"net/http"
"net/url"
"slices"
"strings"
"sync"
"time"
@@ -339,10 +340,8 @@ func (s *URLMetadataService) validateURLForSSRF(u *url.URL) error {
if err != nil {
return ErrSSRFBlocked
}
for _, ip := range ips {
if isPrivateOrReservedIP(ip) {
return ErrSSRFBlocked
}
if slices.ContainsFunc(ips, isPrivateOrReservedIP) {
return ErrSSRFBlocked
}
return nil
}
@@ -359,13 +358,7 @@ func isLocalhost(hostname string) bool {
"0:0:0:0:0:0:0:0",
}
for _, name := range localhostNames {
if hostname == name {
return true
}
}
return false
return slices.Contains(localhostNames, hostname)
}
func isPrivateOrReservedIP(ip net.IP) bool {