Fix linter warnings in gemini/network.go

Remove redundant nil checks before len() operations as len() for nil slices is defined as zero in Go.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-03-10 11:33:56 +02:00
parent efaedcc6b2
commit 658c5f5471
2 changed files with 4 additions and 6 deletions

View File

@@ -17,7 +17,6 @@ import (
_url "gemini-grc/common/url" _url "gemini-grc/common/url"
"gemini-grc/config" "gemini-grc/config"
"gemini-grc/logging" "gemini-grc/logging"
"github.com/antanst/go_errors" "github.com/antanst/go_errors"
"github.com/guregu/null/v5" "github.com/guregu/null/v5"
) )
@@ -217,17 +216,17 @@ func getMimeTypeAndLang(headers string) (int, string, string) {
// - Only capturing the lang value, ignoring charset // - Only capturing the lang value, ignoring charset
re := regexp.MustCompile(`^(\d+)\s+([a-zA-Z0-9/\-+]+)(?:(?:[\s;]+(?:charset=[^;\s]+|lang=([a-zA-Z0-9-]+)))*)\s*$`) re := regexp.MustCompile(`^(\d+)\s+([a-zA-Z0-9/\-+]+)(?:(?:[\s;]+(?:charset=[^;\s]+|lang=([a-zA-Z0-9-]+)))*)\s*$`)
matches := re.FindStringSubmatch(headers) matches := re.FindStringSubmatch(headers)
if matches == nil || len(matches) <= 1 { if len(matches) <= 1 {
// If full format doesn't match, try to match redirect format: "<code> <URL>" // If full format doesn't match, try to match redirect format: "<code> <URL>"
// This handles cases like "31 gemini://example.com" // This handles cases like "31 gemini://example.com"
re := regexp.MustCompile(`^(\d+)\s+(.+)$`) re := regexp.MustCompile(`^(\d+)\s+(.+)$`)
matches := re.FindStringSubmatch(headers) matches := re.FindStringSubmatch(headers)
if matches == nil || len(matches) <= 1 { if len(matches) <= 1 {
// If redirect format doesn't match, try to match just a status code // If redirect format doesn't match, try to match just a status code
// This handles cases like "99" // This handles cases like "99"
re := regexp.MustCompile(`^(\d+)\s*$`) re := regexp.MustCompile(`^(\d+)\s*$`)
matches := re.FindStringSubmatch(headers) matches := re.FindStringSubmatch(headers)
if matches == nil || len(matches) <= 1 { if len(matches) <= 1 {
return 0, "", "" return 0, "", ""
} }
code, err := strconv.Atoi(matches[1]) code, err := strconv.Atoi(matches[1])

View File

@@ -17,7 +17,6 @@ import (
_url "gemini-grc/common/url" _url "gemini-grc/common/url"
"gemini-grc/config" "gemini-grc/config"
"gemini-grc/logging" "gemini-grc/logging"
"github.com/antanst/go_errors" "github.com/antanst/go_errors"
"github.com/guregu/null/v5" "github.com/guregu/null/v5"
) )