From 2fed5c83991af6403f3ca122c2740384f0d04b04 Mon Sep 17 00:00:00 2001 From: Moroka8 Date: Sat, 25 Apr 2026 00:56:17 +0700 Subject: [PATCH] chore: fix: resolve golangci-lint errcheck and govet/shadow warnings --- client/main.go | 2 +- client/manual_captcha.go | 11 +++++++++-- client/slider_captcha.go | 26 ++++++++++++++------------ server/main.go | 14 +++++++++----- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/client/main.go b/client/main.go index 6a1d9b5..2fa2b0a 100644 --- a/client/main.go +++ b/client/main.go @@ -384,7 +384,7 @@ func ParseVkCaptchaError(errData map[string]interface{}) *VkCaptchaError { } // Fallback to top-level session_token field if not in redirect_uri if sessionToken == "" { - if st, ok := errData["session_token"].(string); ok { + if st, stOk := errData["session_token"].(string); stOk { sessionToken = st } } diff --git a/client/manual_captcha.go b/client/manual_captcha.go index 38a444b..4b22569 100644 --- a/client/manual_captcha.go +++ b/client/manual_captcha.go @@ -562,7 +562,11 @@ func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error) isCaptchaRequest := req.Body != nil && (strings.Contains(req.URL.Path, "captchaNotRobot.check") || strings.Contains(req.URL.Path, "captchaNotRobot.componentDone")) if isCaptchaRequest { - b, _ := io.ReadAll(req.Body) + b, err := io.ReadAll(req.Body) + if err != nil { + log.Printf("[Captcha Proxy] Failed to read request body: %v", err) + b = nil + } req.Body = io.NopCloser(bytes.NewReader(b)) if isDebug { @@ -573,7 +577,10 @@ func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error) } if strings.Contains(req.URL.Path, "captchaNotRobot.componentDone") || strings.Contains(req.URL.Path, "captchaNotRobot.check") { - parsedBody, _ := neturl.ParseQuery(string(b)) + parsedBody, err := neturl.ParseQuery(string(b)) + if err != nil { + log.Printf("[Captcha Proxy] Failed to parse request body: %v", err) + } device := parsedBody.Get("device") browserFp := parsedBody.Get("browser_fp") diff --git a/client/slider_captcha.go b/client/slider_captcha.go index cfb08ee..7245546 100644 --- a/client/slider_captcha.go +++ b/client/slider_captcha.go @@ -170,8 +170,8 @@ func (s *captchaNotRobotSession) requestComponentDone() error { respObj, ok := resp["response"].(map[string]interface{}) if ok { - if status, _ := respObj["status"].(string); status != "" && status != "OK" { - return fmt.Errorf("componentDone status: %s", status) + if statusVal, ok := respObj["status"].(string); ok && statusVal != "" && statusVal != "OK" { + return fmt.Errorf("componentDone status: %s", statusVal) } } @@ -294,7 +294,8 @@ func callCaptchaNotRobotWithSliderPOC( time.Sleep(200 * time.Millisecond) log.Printf("[STREAM %d] [Captcha] Step 2/4: componentDone", streamID) - if err := session.requestComponentDone(); err != nil { + err = session.requestComponentDone() + if err != nil { return "", err } @@ -337,7 +338,8 @@ func callCaptchaNotRobotWithSliderPOC( // VK refuses getContent with ERROR because it expects the widget lifecycle. log.Printf("[STREAM %d] [Captcha] Re-registering slider component before getContent...", streamID) time.Sleep(300 * time.Millisecond) - if err := session.requestComponentDone(); err != nil { + err = session.requestComponentDone() + if err != nil { // Non-fatal: log and continue — getContent may still succeed. log.Printf("[STREAM %d] [Captcha] Warning: slider componentDone failed: %v", streamID, err) } @@ -401,7 +403,7 @@ func parseCaptchaSettingsResponse(resp map[string]interface{}) (*captchaSettings settings := &captchaSettingsResponse{ SettingsByType: make(map[string]string), } - settings.ShowCaptchaType, _ = respObj["show_captcha_type"].(string) + settings.ShowCaptchaType, _ = respObj["show_captcha_type"].(string) //nolint:errcheck rawSettings, ok := expandCaptchaSettings(respObj["captcha_settings"]) if !ok { @@ -414,7 +416,7 @@ func parseCaptchaSettingsResponse(resp map[string]interface{}) (*captchaSettings continue } - captchaType, _ := item["type"].(string) + captchaType, _ := item["type"].(string) //nolint:errcheck if captchaType == "" { continue } @@ -580,9 +582,9 @@ func parseCaptchaCheckResult(resp map[string]interface{}) (*captchaCheckResult, } result := &captchaCheckResult{} - result.Status, _ = respObj["status"].(string) - result.SuccessToken, _ = respObj["success_token"].(string) - result.ShowCaptchaType, _ = respObj["show_captcha_type"].(string) + result.Status, _ = respObj["status"].(string) //nolint:errcheck + result.SuccessToken, _ = respObj["success_token"].(string) //nolint:errcheck + result.ShowCaptchaType, _ = respObj["show_captcha_type"].(string) //nolint:errcheck if result.Status == "" { return nil, fmt.Errorf("check status missing: %v", resp) } @@ -596,7 +598,7 @@ func parseSliderCaptchaContentResponse(resp map[string]interface{}) (*sliderCapt return nil, fmt.Errorf("invalid slider content response: %v", resp) } - status, _ := respObj["status"].(string) + status, _ := respObj["status"].(string) //nolint:errcheck if status != "OK" { // Log all fields from the response to help diagnose why VK rejected getContent. var debugFields []string @@ -610,13 +612,13 @@ func parseSliderCaptchaContentResponse(resp map[string]interface{}) (*sliderCapt return nil, fmt.Errorf("slider getContent status: %s", status) } - extension, _ := respObj["extension"].(string) + extension, _ := respObj["extension"].(string) //nolint:errcheck extension = strings.ToLower(extension) if extension != "jpeg" && extension != "jpg" { return nil, fmt.Errorf("unsupported slider image format: %s", extension) } - rawImage, _ := respObj["image"].(string) + rawImage, _ := respObj["image"].(string) //nolint:errcheck if rawImage == "" { return nil, fmt.Errorf("slider image missing") } diff --git a/server/main.go b/server/main.go index cdf91d4..00f871a 100644 --- a/server/main.go +++ b/server/main.go @@ -224,8 +224,8 @@ func handleVLESSConnection(ctx context.Context, dtlsConn net.Conn, connectAddr s return } defer func() { - if err := kcpSess.Close(); err != nil { - log.Printf("failed to close KCP session: %v", err) + if closeErr := kcpSess.Close(); closeErr != nil { + log.Printf("failed to close KCP session: %v", closeErr) } }() log.Printf("KCP session established (server)") @@ -318,7 +318,11 @@ func pipeConn(ctx context.Context, c1, c2 net.Conn) { wg.Wait() - // Reset deadlines - _ = c1.SetDeadline(time.Time{}) - _ = c2.SetDeadline(time.Time{}) + // Reset deadlines (best-effort; connection may already be closed) + if err := c1.SetDeadline(time.Time{}); err != nil { + log.Printf("pipeConn: failed to reset deadline c1: %v", err) + } + if err := c2.SetDeadline(time.Time{}); err != nil { + log.Printf("pipeConn: failed to reset deadline c2: %v", err) + } }